home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cwl2f-3.zip / MANUAL.DOC < prev    next >
Text File  |  1992-04-26  |  709KB  |  21,707 lines

  1. @ME.FORMAT                                                              R        
  2.                         THE C WINDOW LIBRARY
  3.             (c) Copyright P. A. McKenzie 1990, 1991, 1992
  4.                          All Rights Reserved
  5.  
  6.                              Version 2.0e
  7.  
  8.  
  9.                   T A B L E   O F   C O N T E N T S
  10.  
  11.  
  12.          PRELIMINARIES .........................................  i
  13.             Microsoft C ........................................  i
  14.             Turbo C/C++/Borland C++ ............................  ii
  15.             Power C ............................................  ii
  16.             Zortech C++ ........................................  iii
  17.  
  18.          INTRODUCTION ........................................... 1
  19.             Defining Windows .................................... 1
  20.             Properties of Windows ............................... 1
  21.             Writing to Overlapping Windows ...................... 2
  22.             Window Ranks ........................................ 2
  23.             Detection of Video Hardware ......................... 2
  24.             Window Coordinates .................................. 2
  25.             Video Attributes .................................... 3
  26.             Direct Screen Writes and BIOS Screen Updates ........ 4
  27.             Video Paging ........................................ 5
  28.             Error Codes ......................................... 6
  29.             Window Manager ...................................... 8
  30.  
  31.  
  32.          MANDATORY FUNCTIONS AND HEADER FILES ................... 9
  33.             WindowInitializeSystem() ............................ 9
  34.  
  35.  
  36.          CREATING WINDOWS ....................................... 10
  37.             The WINDOW structure and WPOINTER structure pointer . 10
  38.             WindowSaveInitial() ................................. 10
  39.             WindowInitialize() .................................. 11
  40.             CREATE_VIDEO_ATTRIBUTE() macro ...................... 12
  41.             Box types ........................................... 12
  42.  
  43.  
  44.          OPENING WINDOWS FOR READING AND WRITING ................ 15
  45.             WindowOpen() ........................................ 15
  46.  
  47.  
  48.          DISPLAYING WINDOWS ..................................... 16
  49.             The WindowDisplay() function and Explosion Effects .. 16
  50.             Displaying Multiple Windows ......................... 19
  51.  
  52.  
  53.          CLOSING WINDOWS ........................................ 21
  54.             WindowClose() ....................................... 21
  55.             WindowFree() ........................................ 22
  56.             WindowCloseAll() .................................... 23
  57.             WindowFreeAll() ..................................... 24
  58.  
  59.  
  60.          CENTERING WINDOWS ON THE SCREEN ........................ 25
  61.             WindowCenter() ...................................... 25
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                            The C Window Library
  68.  
  69.          CHANGING WINDOW CHARACTERISTICS ........................ 27
  70.             WindowChangeTextAttribute() ......................... 27
  71.             WindowChangeBorderAttribute() ....................... 28
  72.             WindowDrawBorder() .................................. 28
  73.             WindowRemoveBorder() ................................ 30
  74.             WindowResizeHeight() ................................ 30
  75.             WindowResizeWidth() ................................. 31
  76.  
  77.  
  78.          WRITING TEXT TO WINDOWS ................................ 33
  79.  
  80.             Null Terminated Write Functions ..................... 33
  81.                WindowWriteString() .............................. 33
  82.                WindowWriteStringAttr() .......................... 34
  83.                WindowWriteCenterString() ........................ 35
  84.                WindowWriteCenterStringAttr() .................... 36
  85.                WindowWriteStringCC() ............................ 36
  86.                WindowWriteStringCCAttr() ........................ 37
  87.                WindowWriteStringRJ() ............................ 38
  88.                WindowWriteStringRJAttr() ........................ 39
  89.  
  90.             Length Controlled Write Functions.................... 40
  91.                WindowWriteCharacters() .......................... 40
  92.                WindowWriteAttributes() .......................... 41
  93.                WindowWriteCharAndAttr() ......................... 42
  94.                WindowWriteCharactersAttr() ...................... 43
  95.                WindowWriteRepeatAttribute() ..................... 44
  96.                WindowWriteRepeatCharacter() ..................... 45
  97.  
  98.             Formatted Write Functions ........................... 46
  99.                Where output is placed in the window ............. 46
  100.                WindowSetWrap() .................................. 46
  101.                WindowPrintf() ................................... 47
  102.                WindowPrintfAttr() ............................... 48
  103.  
  104.  
  105.          WRITING TITLES TO WINDOWS .............................. 50
  106.             WindowTitleTop() .................................... 51
  107.             WindowTitleBottom() ................................. 52
  108.             WindowTitleTopAttr() ................................ 53
  109.             WindowTitleBottomAttr() ............................. 54
  110.  
  111.  
  112.          READING CHARACTERS AND ATTRIBUTES FROM WINDOWS ......... 56
  113.             WindowReadCharacters() .............................. 56
  114.             WindowReadAttributes() .............................. 57
  115.             WindowReadCharAndAttr() ............................. 58
  116.  
  117.  
  118.          HIDING WINDOWS ......................................... 60
  119.             WindowHide() ........................................ 60
  120.  
  121.  
  122.          CREATING COPIES OF A WINDOW ............................ 62
  123.             WindowCopy() ........................................ 62
  124.  
  125.  
  126.  
  127.                            The C Window Library
  128.  
  129.          SCROLLING TEXT IN WINDOWS .............................. 64
  130.             WindowScroll() ...................................... 64
  131.             WindowScrollRegion() ................................ 65
  132.             WindowScrollAttr() .................................. 66
  133.             WindowScrollRegionAttr() ............................ 67
  134.  
  135.  
  136.          CLEARING WINDOWS ....................................... 69
  137.             WindowClear() ....................................... 69
  138.             WindowClearAttr() ................................... 70
  139.             WindowClearRegion() ................................. 70
  140.             WindowClearRegionAttr() ............................. 71
  141.  
  142.  
  143.          WRITING WINDOW CONTENTS TO A FILE ...................... 73
  144.             WindowWriteTextToFile() ............................. 73
  145.  
  146.  
  147.          SHADOWING WINDOWS ...................................... 75
  148.             WindowDrawShadow() .................................. 75
  149.             WindowRemoveShadow() ................................ 77
  150.  
  151.  
  152.          SEE-THRU WINDOWS ....................................... 78
  153.             WindowMakeSeeThru() ................................. 78
  154.             WindowMakeNormal() .................................. 79
  155.  
  156.  
  157.          MOVING AND SLIDING WINDOWS ............................. 80
  158.             WindowMove() ........................................ 80
  159.             WindowSlide() ....................................... 81
  160.  
  161.  
  162.          CURSOR POSITIONING IN WINDOWS .......................... 82
  163.             Cursor Maintenance in The C Window Library .......... 82
  164.             Creating Cursor Shapes .............................. 82
  165.             WindowChangeCursor() ................................ 82
  166.             WindowMoveCursor() .................................. 83
  167.             WindowGetCursorShape() .............................. 84
  168.             WindowGetCursorPosition() ........................... 85
  169.  
  170.  
  171.          GETTING WHICH WINDOW OCCUPIES A LOCATION ............... 87
  172.             WindowWhich() ....................................... 87
  173.  
  174.  
  175.          GETTING INPUT FROM WINDOWS ............................. 88
  176.             Input Manager ....................................... 88
  177.             Regular Expressions ................................. 88
  178.             Editing Input ....................................... 93
  179.             Last Key Value ...................................... 95
  180.             Default Cursor Types and Editing Mode ............... 96
  181.             Editing using a character mask ...................... 97
  182.  
  183.  
  184.  
  185.  
  186.  
  187.                            The C Window Library
  188.  
  189.             Editing Functions ................................... 97
  190.                WindowGetString() ................................ 97
  191.                WindowGetStringAttr() ............................ 99
  192.                WindowGetMaskString() ............................ 100
  193.                WindowGetMaskStringAttr() ........................ 102
  194.                Getting Passwords ................................ 103
  195.                   WindowGetPassword() ........................... 103
  196.                   WindowGetPasswordAttr() ....................... 104
  197.                   WindowGetMaskPassword() ....................... 105
  198.                   WindowGetMaskPasswordAttr() ....................106
  199.                Undefined Keystroke Processing ................... 107
  200.                     The undef_fkey_func and undef_akey_func
  201.                               function pointers ................. 107
  202.                     Specifying when to call an undefined key
  203.                           function in a Regular Expression ...... 108
  204.                     Return Values To The Input Manager .......... 109
  205.  
  206.  
  207.                Input Options .................................... 112
  208.                CHECKREGEXP and the reg_exp_error_func
  209.                      function pointer ........................... 113
  210.                THE num_chars_entered_func FUNCTION POINTER ...... 116
  211.  
  212.  
  213.                Other Input releated functions ................... 117
  214.                TranslateStringToMaskString() .................... 117
  215.                TranslateMaskStringToString() .................... 119
  216.  
  217.  
  218.          VIRTUAL WINDOWS ........................................ 121
  219.             Using Windows as Viewports .......................... 121
  220.             Attributed and Non-Attributed Virtual Windows ....... 121
  221.             Virtual Window's Logical Cursor ..................... 122
  222.  
  223.  
  224.             CREATING VIRTUAL WINDOWS ............................ 123
  225.                VirtualInitialize() .............................. 123
  226.  
  227.  
  228.             ASSIGNING VIEWPORTS AND CLOSING VIEWPORTS ........... 125
  229.                WindowAssignToVirtual() .......................... 125
  230.                Out of bounds Coordinates ........................ 126
  231.                WindowCloseViewport() ............................ 127
  232.  
  233.  
  234.             WRITING TEXT TO VIRTUAL WINDOWS ..................... 129
  235.  
  236.                Null Terminated String Functions ................. 129
  237.                   VirtualWriteString() .......................... 129
  238.                   VirtualWriteStringAttr() ...................... 130
  239.                   VirtualWriteCenterString() .................... 131
  240.                   VirtualWriteCenterStringAttr() ................ 132
  241.                   VirtualWriteStringCC() ........................ 133
  242.                   VirtualWriteStringCCAttr() .................... 134
  243.                   VirtualWriteStringRJ() ........................ 135
  244.                   VirtualWriteStringRJAttr() .................... 136
  245.  
  246.  
  247.                            The C Window Library
  248.  
  249.                Length Controlled Functions ...................... 137
  250.                   VirtualWriteCharacters() ...................... 137
  251.                   VirtualWriteAttributes() ...................... 138
  252.                   VirtualWriteCharAndAttr() ..................... 139
  253.                   VirtualWriteRepeatAttribute() ................. 140
  254.                   VirtualWriteRepeatCharacter() ................. 141
  255.  
  256.                Formatted Write Functions ........................ 142
  257.                   Format String ................................. 142
  258.                   Where Output is Placed ........................ 142
  259.                   VirtualSetWrap() .............................. 142
  260.                   VirtualPrintf() ............................... 143
  261.                   VirtualPrintfAttr() ........................... 144
  262.  
  263.  
  264.             READING CHARACTERS AND ATTRIBUTES FROM
  265.                                    VIRTUAL WINDOWS .............. 146
  266.                VirtualReadCharacters() .......................... 146
  267.                VirtualReadAttributes() .......................... 147
  268.                VirtualReadCharAndAttr() ......................... 148
  269.  
  270.  
  271.             REPOSITIONING THE VIEWPORT .......................... 150
  272.                WindowPositionViewport() ......................... 150
  273.  
  274.  
  275.             SCROLLING THE VIEWPORTS ............................. 154
  276.                WindowScrollVirtual() ............................ 154
  277.  
  278.  
  279.             WRITING VIRTUAL WINDOW CONTENTS TO A FILE ........... 157
  280.                VirtualWriteTextToFile() ......................... 157
  281.  
  282.  
  283.             MOVING THE LOGICAL CURSOR ........................... 159
  284.                VirtualMoveCursor() .............................. 159
  285.                VirtualGetCursorPosition() ....................... 159
  286.  
  287.  
  288.             CLEARING VIRTUAL WINDOWS ............................ 161
  289.                VirtualClear() ................................... 161
  290.                VirtualClearAttr() ............................... 162
  291.                VirtualClearRegion() ............................. 162
  292.                VirtualClearRegionAttr() ......................... 163
  293.  
  294.  
  295.             FREEZING VIEWPORTS .................................. 165
  296.                WindowFreeze() ................................... 165
  297.  
  298.  
  299.             DISPOSING OF VIRTUAL WINDOWS ........................ 167
  300.                VirtualFree() .................................... 167
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.                            The C Window Library
  308.  
  309.          INTRODUCTION TO MENU SYSTEM ............................ 169
  310.             Menu Manager ........................................ 169
  311.             Necessary "include" files ........................... 169
  312.  
  313.  
  314.             POP-UP MENUS ........................................ 170
  315.                Description ...................................... 170
  316.                Windows and Virtual Windows ...................... 170
  317.  
  318.  
  319.             CREATING POP-UP MENUS ............................... 171
  320.                The POPUP_MENU_ENTRY structure ................... 171
  321.                   Defining Hotkeys .............................. 172
  322.                   Assigning the function to perform ............. 173
  323.                Coloring Popup Menus ............................. 173
  324.                Creating Popup Menu Entries Dynamically .......... 174
  325.                PopupCreateMenu() function ....................... 179
  326.                   Popup Menu Options ............................ 180
  327.                   Default Popup Window and Creating
  328.                                    Your own Windows ............. 182
  329.                   Default Virtual Window and
  330.                         Creating Your own Virtual Windows ....... 184
  331.                   Accessing Popup Windows and Virtual Windows ... 184
  332.                   Warnings ...................................... 185
  333.                   Return Values for PopupCreateMenu() ........... 185
  334.  
  335.  
  336.             SELECTING FROM POPUP MENUS .......................... 187
  337.                PopupSelectMenu() function ....................... 187
  338.                   Values passed to menu function ................ 189
  339.                   Values returned to menu manager ............... 189
  340.                   Return Values for PopupSelectMenu() ........... 190
  341.  
  342.  
  343.             SETTING OPTIONS IN POPUP MENUS ...................... 191
  344.                The PopupSetOptions() function ................... 191
  345.                   Setting Multiple Options ...................... 192
  346.                   Setting the PopupSetConfirmFunction() ......... 192
  347.                   Return Values for PopupSetOptions() function .. 193
  348.  
  349.  
  350.             MAKING MENU ENTRIES AVAILABLE AND UNAVAILABLE ....... 194
  351.                PopupMakeEntryAvailable() and
  352.                PopupMakeEntryUnavailable() functions ............ 194
  353.                   POPUPOVERRIDE option .......................... 194
  354.                Return Values for PopupMakeEntryAvaialble() and
  355.                PopupMakeEntryUnavailable() functions ............ 194
  356.  
  357.  
  358.             CHANGING THE MENU ENTRY STRINGS ..................... 196
  359.                PopupChangeEntryString() function ................ 196
  360.                Return Values for PopupChangeEntryString()
  361.                                         function ................ 196
  362.  
  363.  
  364.  
  365.  
  366.  
  367.                            The C Window Library
  368.  
  369.             REDEFINING MENU KEYS ................................ 197
  370.                Setting Global Key Definitions and
  371.                       the popup_key_definition Array ............ 197
  372.                Setting Local Key Definitions .................... 197
  373.                   PopupAssignKeys() function .................... 198
  374.                   Return Values for PopupAssignKeys() function .. 198
  375.  
  376.  
  377.             PROCESSING UNDEFINED KEYS ........................... 199
  378.                The popup_undef_key function pointer ............. 199
  379.                   Values returned to menu manager ............... 199
  380.  
  381.  
  382.             PRE-INPUT FUNCTION .................................. 203
  383.                Setting the global_popup_prefunc
  384.                                   function pointer .............. 203
  385.  
  386.  
  387.             DISPOSING OF POPUP MENUS ............................ 205
  388.                PopupMenuFree() .................................. 205
  389.                Return Values for PopupMenuFree() ................ 205
  390.  
  391.  
  392.          BAR MENUS .............................................. 206
  393.             Description ......................................... 206
  394.             Windows and Virtual Windows ......................... 206
  395.             CREATING BAR MENUS .................................. 207
  396.                The BAR_MENU_ENTRY structure ..................... 207
  397.                   Defining Hotkeys .............................. 208
  398.                   Assigning the function to perform ............. 209
  399.                Coloring Bar Menus ............................... 209
  400.                Creating Bar Menu Entries Dynamically ............ 210
  401.                BarCreateMenu() function ......................... 214
  402.                   Bar Menu Options .............................. 215
  403.                   Default Bar Menu Window and Creating
  404.                                       Your own Windows .......... 217
  405.                   Accessing bar menu windows .................... 219
  406.                   Warnings ...................................... 219
  407.                   Return Values for BarCreateMenu() ............. 219
  408.  
  409.  
  410.             SELECTING FROM BAR MENUS ............................ 221
  411.                BarSelectMenu() function ......................... 221
  412.                   Values passed to menu function ................ 223
  413.                   Values returned to menu manager ............... 223
  414.                   Return Values for BarSelectMenu() ............. 223
  415.  
  416.  
  417.             SETTING OPTIONS IN BAR MENUS ........................ 225
  418.                The BarSetOptions() function ..................... 225
  419.                   Setting Multiple Options ...................... 226
  420.                   Setting the BarSetConfirmFunction() ........... 226
  421.                   Return Values for BarSetOptions() function .... 227
  422.  
  423.  
  424.  
  425.  
  426.  
  427.                            The C Window Library
  428.  
  429.             MAKING ENTRIES AVAILABLE AND UNAVAILABLE ............ 228
  430.                BarMakeEntryAvailable() and
  431.                BarMakeEntryUnavailable() functions .............. 228
  432.                   BAROVERRIDE option ............................ 228
  433.                Return Values for BarMakeEntryAvaialble() and
  434.                BarMakeEntryUnavailable() functions .............. 228
  435.  
  436.  
  437.             CHANGING THE MENU OPTIONS STRING .................... 230
  438.                BarChangeEntryString() function .................. 230
  439.                   Return Values for BarChangeEntryString()
  440.                   function ...................................... 230
  441.  
  442.  
  443.             REDEFINING THE MENU KEYS ............................ 232
  444.                Setting Global Key Definitions and
  445.                      the bar_key_definition Array ............... 232
  446.                Setting Local Key Definitions .................... 232
  447.                   BarAssignKeys() function ...................... 232
  448.                   Return Values for BarAssignKeys() function .... 233
  449.  
  450.  
  451.             PROCESSING UNDEFINED KEYS ........................... 234
  452.                The bar_undef_key function pointer ............... 234
  453.                   Values returned to menu manager ............... 234
  454.  
  455.  
  456.             PRE-INPUT FUNCTION .................................. 237
  457.                Setting the global_bar_prefunc function pointer... 237
  458.  
  459.  
  460.             DISPOSING OF BAR MENUS .............................. 239
  461.                BarMenuFree() function ........................... 239
  462.                Return Values for BarMenuFree() .................. 239
  463.  
  464.  
  465.          PULLDOWN MENUS ......................................... 240
  466.             Description ......................................... 240
  467.             Bar Menu and Popup Menu levels ...................... 240
  468.  
  469.  
  470.             CREATING PULLDOWN MENUS ............................. 241
  471.                The PulldownCreateMenu() function ................ 242
  472.                   Automatic Adjustment of Popup Windows ......... 244
  473.                Return values for PulldownCreateMenu() ........... 247
  474.  
  475.  
  476.             SELECTING FROM PULLDOWN MENUS ....................... 248
  477.                The PulldownSelectMenu() function ................ 248
  478.                   Immediate Mode ................................ 248
  479.                   Values passed to the selected menu function ... 249
  480.                   Values returned to the menu manager ........... 249
  481.                   Return Values for PulldownSelectMenu() ........ 249
  482.  
  483.  
  484.  
  485.  
  486.  
  487.                            The C Window Library
  488.  
  489.             REDEFINING KEY DEFINITIONS .......................... 250
  490.  
  491.  
  492.                REDEFINING KEY DEFINITIONS FOR POPUP MENUS ....... 251
  493.                   Setting Popup Menu Global Key Definitions ..... 251
  494.                   Setting Popup Menu Local Definitions .......... 252
  495.  
  496.                REDEFINING KEY DEFINITIONS FOR THE BAR MENU ...... 253
  497.                   Setting bar menu global key definitions ....... 253
  498.                   Setting Bar Menu Local definitions ............ 253
  499.  
  500.  
  501.             PROCESSING UNDEFINED POPUP MENU KEYS ................ 254
  502.  
  503.  
  504.             PROCESSING UNDEFINED BAR MENU KEYS .................. 255
  505.  
  506.  
  507.  
  508.  
  509.             DISPOSING OF PULLDOWN MENUS ......................... 256
  510.                The PulldownMenuFree() function .................. 256
  511.                The PulldownMenuFreeAll() function ............... 256
  512.  
  513.  
  514.             SUMMARY OF PULLDOWN MENUS ........................... 257
  515.  
  516.  
  517.             EXAMPLE OF PULLDOWN MENU SYSTEM ..................... 258
  518.  
  519.  
  520.          MISCELLANEOUS FUNCTIONS ................................ 262
  521.  
  522.  
  523.             SETTING AND CHECKING VIDEO PAGES .................... 262
  524.                CheckVideoPage() ................................. 262
  525.                SetActiveVideoPage() function .................... 263
  526.                SetVisibleVideoPage() function ................... 264
  527.  
  528.  
  529.             GENERAL STRING WRITING FUNCTIONS .................... 266
  530.                VideoWriteString() ............................... 266
  531.                VideoWriteStringAttr() ........................... 267
  532.                VideoWriteAttributes() ........................... 267
  533.                VideoWriteCenterString() ......................... 268
  534.                VideoWriteCenterStringAttr() ..................... 269
  535.                VideoWriteCharAndAttr() .......................... 269
  536.                VideoWriteStringCC() ............................. 270
  537.                VideoWriteStringCCAttr() ......................... 271
  538.                VideoWriteStringRJ() ............................. 271
  539.                VideoWriteStringRJAttr() ......................... 272
  540.                VideoPrintf() .................................... 273
  541.                VideoPrintfAttr() ................................ 273
  542.  
  543.  
  544.  
  545.  
  546.  
  547.                            The C Window Library
  548.  
  549.             READING CHARACTERS AND ATTRIBUTES FROM THE SCREEN ... 275
  550.                VideoReadCharacters() ............................ 275
  551.                VideoReadAttributes() ............................ 275
  552.                VideoReadCharAndAttr() ........................... 276
  553.  
  554.  
  555.             DRAWING BOXES ....................................... 277
  556.                VideoDrawBox() ................................... 277
  557.                VideoDrawBoxAttr() ............................... 277
  558.  
  559.  
  560.             SAVING AND RESTORING SCREEN IMAGES .................. 279
  561.                VideoSave() ...................................... 279
  562.                VideoMove() ...................................... 280
  563.                VideoRestore() ................................... 280
  564.                VideoFree() ...................................... 281
  565.  
  566.  
  567.  
  568.             CLEARING SCREENS .................................... 282
  569.                ClearScreen() .................................... 282
  570.                ClearRegion() .................................... 282
  571.  
  572.  
  573.             SCROLLING SCREENS ................................... 284
  574.                ScrollScreenUp() ................................. 284
  575.                ScrollScreenDown() ................................284
  576.  
  577.  
  578.             CHANGING THE VIDEO MODE ............................. 286
  579.                SetVideoMode() ................................... 286
  580.  
  581.  
  582.             CHANGING THE NUMBER OF ROWS AND COLUMNS ON
  583.                                         THE SCREEN .............. 287
  584.                Changing rows .................................... 287
  585.                   AdjustScreenInfo() ............................ 287
  586.                   AdjustGlobalData() ............................ 288
  587.                   SetVideoRows() ................................ 288
  588.                Changing columns ................................. 291
  589.                   40 column and 80 column modes ................. 291
  590.                   Modes higher than 80 columns .................. 292
  591.  
  592.  
  593.             CURSOR MANIPULATION ................................. 294
  594.                MoveCursor() ..................................... 294
  595.                ChangeCursor() ................................... 294
  596.                GetCursorShape() ................................. 295
  597.                GetCursorPosition() .............................. 295
  598.                HideCursor() ..................................... 296
  599.                BlockCursor() .................................... 296
  600.                ThinCursor() ..................................... 296
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.                            The C Window Library
  608.  
  609.             GETTING VIDEO INFORMATION ........................... 298
  610.                VIDEO_CONFIG structure ........................... 298
  611.                GetVideoBiosInfo() ............................... 298
  612.  
  613.  
  614.             TIMED DELAYS ........................................ 300
  615.                delay() .......................................... 300
  616.  
  617.  
  618.             SOUND FUNCTIONS ..................................... 301
  619.                sound() and nosound() ............................ 301
  620.                MakeSound() ...................................... 301
  621.  
  622.  
  623.             ERROR HANDLING ...................................... 303
  624.                The window_error_func function pointer ........... 303
  625.  
  626.  
  627.             USING A MOUSE WITH THE C WINDOW LIBRARY ............. 306
  628.                Installing the Mouse Library ..................... 306
  629.                Include Files .................................... 306
  630.                Initializing the Mouse with
  631.                                 MouseInitializeSystem().......... 306
  632.                Turning off the mouse with MouseRestoreSystem() .. 307
  633.                Using a mouse with popup menus ................... 308
  634.                    Popup Menu's prefunction for mouse ........... 310
  635.                Using a mouse with bar menus ..................... 311
  636.                Using a mouse with pulldown menus ................ 313
  637.                Changing the mouse defaults ...................... 314
  638.  
  639.  
  640.             WINDOW AND VIRTUAL WINDOW MACROS .................... 315
  641.  
  642.  
  643.             MENU MACROS ......................................... 318
  644.                Popup Menu Macros ................................ 318
  645.                Bar Menu Macros .................................. 320
  646.                Pulldown Menu Macros ............................. 321
  647.  
  648.  
  649.             VIDEO MACROS ........................................ 322
  650.  
  651.             BOX MACROS .......................................... 326
  652.  
  653.             EXPLOSION MACROS .................................... 327
  654.  
  655.             KEYBOARD MACROS ..................................... 328
  656.               Keyboard Idle Function ............................ 329
  657.               Keyboard Intercept Function ....................... 330
  658.               Checking for mouse presses ........................ 331
  659.  
  660.             CURSOR MACROS ....................................... 333
  661.  
  662.  
  663.          IMPORTANT GLOBAL VARIABLES ............................. 334
  664.  
  665.  
  666.  
  667.                            The C Window Library
  668.  
  669.                             PRELIMINARIES
  670.                             -------------
  671.  
  672.          Congratulations on using The C Window Library; the easiest to 
  673.          use, most powerful, inexpensive C user interface library!
  674.          Before we start talking 'C', we will discuss briefly on how 
  675.          to compile and link programs using The C Window Library.
  676.  
  677.          The following discussion is very brief.  For more in depth 
  678.          information on make files, project files, link options, etc. 
  679.          please consult the various documentation supplied with the 
  680.          compiler that you are working with.  
  681.  
  682.          The default word/byte alignment scheme was used when 
  683.          compiling all the libraries.  In other words, all modules 
  684.          used by The C Window Library were compiled without the use of 
  685.          the word/byte alignment switch being used.
  686.  
  687.  
  688.          Microsoft / Quick C
  689.          -------------------
  690.  
  691.          When compiling your programs, you must make sure that the 
  692.          constant MSC is defined.  An example of how you would do this 
  693.          as follows:
  694.  
  695.          cl -Ax -DMSC -Ihfiles prog1.c /link mswinx.lib msmousex.lib
  696.  
  697.          the -Ax is the model used for compilation.  The x stands for 
  698.          either S for small, M for medium, C for compact, or L for 
  699.          large.  The -D option defines a constant, which in this case 
  700.          is MSC.  You must use the -D switch with MSC as the constant.  
  701.          If not, you will get either syntax errors, link errors, or 
  702.          runtime errors.  The -I option tells the compiler that the .h 
  703.          files are located in a directory on the default drive called 
  704.          hfiles.  The /link option links the resulting object files 
  705.          (prog1.obj) with The C Window Library file mswinx.lib, where 
  706.          x stands for S, M, C, or L.  The mouse library msmousex.lib, 
  707.          where x stands for S, M, C, or L, is necessary only if you 
  708.          plan to use the mouse in your application.
  709.  
  710.          The other method is to create a make file.  If you are using 
  711.          the integrated environment of Quick C or using the 
  712.          Programmers Work Bench (PWB) for Microsoft C 6.0, you can 
  713.          create your make files by selecting the files you want to 
  714.          compile, and the libraries you want to link with and letting 
  715.          these integrated environments create the make file 
  716.          automatically.  If you are more advanced you can create your 
  717.          make files by yourself without the aid of these programs.  
  718.          Consult the documentation for more information on make files.
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.                                   i
  728.  
  729.          Turbo C/TurboC++/Borland C++
  730.          ----------------------------
  731.  
  732.          If you will use the integrated environment, you must create a 
  733.          project file.  This project file specifies the source code 
  734.          modules, object code modules, and libraries that will be 
  735.          linked in to produce an executable file.  If you use the 
  736.          Turbo C Version 2.0 integrated environment, you must edit 
  737.          this file yourself.  If you use the Turbo C++ or Borland C++ 
  738.          integrated environment, use the automatic Project File 
  739.          creator.
  740.  
  741.          You can also use make files to link in your program.  Make 
  742.          sure that the desired library from The C Window Library is 
  743.          specified.
  744.  
  745.          You can also use the TCC.EXE (or BCC if you are using 
  746.          Borland C++) command line compiler with the desired library 
  747.          specified on the command line.  Consult the Turbo C/C++ 
  748.          documentation on using make files and using the integrated 
  749.          environment.
  750.  
  751.          The default structure alignment was used to compile the 
  752.          libraries, which is byte alignment.
  753.  
  754.          An example of using the TCC.EXE (BCC.EXE) command line is as 
  755.          follows:
  756.  
  757.          tcc -mm -G -r -ihfiles prog1.c tcwinm.lib tcmousem.lib
  758.  
  759.          The following command line uses -mm for the medium memory 
  760.          model, -G to optimize for speed, -r for usage of register 
  761.          variables, and -i to tell the compiler that the header files 
  762.          are located in a directory on the default drive called 
  763.          hfiles.  The mouse library, tcmousem.lib, is necessary only 
  764.          if you plan to use the mouse in your application.
  765.  
  766.  
  767.          Power C 
  768.          -------
  769.  
  770.          If you are using the POWER C compiler from Mix Software, you 
  771.          must define the constant POWERC on the command line.
  772.  
  773.                      pc -dPOWERC -mm -ihfiles prog1.c
  774.  
  775.          You must have the constant POWERC defined on the pc.exe 
  776.          command line using the -d option.  If not, you may get 
  777.          syntax, link, or runtime errors.  The -mm tells the compiler 
  778.          to use the medium memory model, and the -i option tells the 
  779.          compiler that there are .h files located on the default drive 
  780.          in the directory hfiles.
  781.  
  782.          Depending on the number of windows your application will use 
  783.          and the code size, you will have to use different stack and 
  784.          heap options in the Power C linker, pcl.  An example of this 
  785.          is as follows:
  786.  
  787.                                  ii
  788.  
  789.                      pcl [20k,30k,200k] a;pcwinm;pcmousem
  790.  
  791.          This will link the object file a.mix with the pcwinm.mix 
  792.          library with 20k of stack space, 30k of near heap space, and 
  793.          200k of far heap space.  If your application has many or very 
  794.          large virtual windows, you should use the maximum far heap 
  795.          space allowable.  If your program has many windows, you 
  796.          should increase the near heap space parameter, or use the 
  797.          pcwinl.mix library and increase the far heap space parameter.  
  798.          If your program has recursive or deeply nested functions, you 
  799.          should increase the stack parameter.  However the stack and 
  800.          near heap space cannot exceed 64k.  This includes global and 
  801.          static declarations in the program.  The mouse library, 
  802.          pcmousex, is necessary only if you plan to use the mouse in 
  803.          your application.
  804.  
  805.  
  806.  
  807.          Zortech C++
  808.          -----------
  809.  
  810.          If you are using the Zortech C++ compiler, you should use 
  811.          the following options when compiling your program with The C 
  812.          Window Library:
  813.  
  814.               ztc -o -b -p -mm prog1.c zcwinm.lib zcmousem.lib
  815.  
  816.          The -o option turns on the global optimizer.  The -b option 
  817.          lets ztc know to handle large programs.  The -p turns off 
  818.          auto-prototyping.  The -mm option lets the compiler use the 
  819.          medium memory model.  The programs prog1.c is compiled using 
  820.          these options and then linked with the medium memory model of 
  821.          The C Window Library's Zortech version, namely zcwinm.lib.
  822.  
  823.          The mouse library, zcmousem.lib, is necessary only if you 
  824.          plan to use the mouse in your application.
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.                                  iii
  848.  
  849.                             INTRODUCTION
  850.                             ------------
  851.  
  852.          Defining Windows
  853.          ----------------
  854.  
  855.          A window is an area of the screen that is separate and
  856.          independent from the other areas of the screen.  With
  857.          windows, you can scroll, write text, delete text, etc. in a
  858.          defined section of the screen.  An example of windows in
  859.          application programs are the resident memory utilities that
  860.          pop up on the screen when invoked, and restore the text to
  861.          its original state when the resident application is
  862.          terminated.  Sidekick is a good example of what you can do
  863.          with windows.  As a matter of fact, most professional
  864.          programs use windows in some manner.  Some applications use
  865.          windows to make pulldown menus i.e. the integrated
  866.          environment in the Turbo languages and in Microsoft Quick
  867.          C's integrated environment.  Other applications such as text
  868.          editors and word processors use windows to display and edit
  869.          a files contents.  With The C Window Library, you can create
  870.          professional looking application program easily and without
  871.          worrying about the tricky details of window management.  At
  872.          your disposal are tools that can help you create pull-down
  873.          menus, popup menus, bar menus, and just fast output.
  874.  
  875.  
  876.          Properties of Windows
  877.          ---------------------
  878.  
  879.          Windows should have the following properties:
  880.            - more than one window can be displayed on the screen
  881.              simultaneously.
  882.  
  883.            - windows are allowed to overlap without disturbing the
  884.              contents of the windows underneath.
  885.  
  886.            - a window that is under a pile of windows can be brought
  887.              to the top.
  888.  
  889.            - a window that is under a pile of windows can be written
  890.              to without interfering with other windows.
  891.  
  892.            - windows can be disposed of when not needed, and erased
  893.              from the screen.  When erased, the contents of the
  894.              screen underneath the window is restored.
  895.  
  896.            - windows can be written to at any time.
  897.  
  898.            - the window application should automatically detect the
  899.              type of video hardware used.
  900.  
  901.            - the window functions should return an error if something
  902.              goes wrong.
  903.  
  904.  
  905.  
  906.  
  907.          Page 1          The C Window Library               Page 1
  908.  
  909.          Writing to Overlapping Windows
  910.          ------------------------------
  911.  
  912.          With The C Window Library, if a window does overlap another
  913.          window, this overlap will be displayed on the physical
  914.          screen.  The C Window Library allows you to direct output to
  915.          any window at any time.  When output is written to a window,
  916.          the window contents are updated in memory, but only the
  917.          visible portions of the window will be updated on the screen.
  918.  
  919.  
  920.          Window Ranks
  921.          ------------
  922.  
  923.          The rank order of the windows on the screen will determine
  924.          which window has priority of the screen.
  925.  
  926.          Windows with lower rank numbers overlap windows with higher
  927.          rank numbers.  The lowest rank number is 1, and the highest
  928.          is 254.  If a new window is opened with the same rank number
  929.          as another previously opened window, the new window takes
  930.          over the rank position, and the previous window's rank is
  931.          increased by 1.   If there is a window with the same rank as
  932.          the previous window's new rank, its rank is increased by 1
  933.          etc.  When a window is closed, all windows with a higher
  934.          rank number are decreased by 1.
  935.  
  936.  
  937.  
  938.          Detection of Video Hardware
  939.          ---------------------------
  940.  
  941.          With The C Window Library, automatic detection of the type
  942.          of video hardware is necessary.  Since The C Window Library
  943.          can write directly to screen memory, the starting memory
  944.          address of screen memory must be known.  Depending on the
  945.          video adapter, the starting address of screen memory is
  946.          different.  For monochrome systems, the starting address is
  947.          different from a color system.  If the window routines think
  948.          that they are writing to a color system instead of a
  949.          monochrome system, crazy things will probably happen.  For
  950.          most adapters, The C Window Library will detect them and
  951.          assign the starting address of screen memory to a global
  952.          variable, so there is no need to specify the starting
  953.          address yourself.
  954.  
  955.  
  956.          Window Coordinates
  957.          ------------------
  958.  
  959.          A position on the screen can be specified as a pair of
  960.          numbers.  These numbers will denote the row and column of
  961.          the desired position.  Rows and columns are numbered from 1
  962.          to the maximum row or column number.  The upper left hand
  963.          corner of the screen would be at row 1, column 1.  For
  964.  
  965.  
  966.  
  967.          Page 2          The C Window Library               Page 2
  968.  
  969.          simplicity, row y, column x will be abbreviated as (y,x).
  970.          The position (1,1) is called  the home position.
  971.  
  972.          However, when specifying a position in a window, this
  973.          position is numbered relative to the window itself.  No
  974.          matter where a window resides on the screen, the upper left
  975.          position of the window is (1,1), the second row of the
  976.          window is row 2, the fourth column is column 4, etc.  The
  977.          window coordinates are called window relative coordinates.
  978.          There are some window functions that require you to enter
  979.          physical screen (absolute) coordinates, but for most
  980.          functions, a window relative position would be needed.  For
  981.          example:
  982.  
  983.          -----------------------------------------------------------
  984.          |(1,1)                                              (80,1)|
  985.          |                                                         |
  986.          |                Valid Absolute Screen Coordinates        |
  987.          |                      For 80 x 25 Screen                 |
  988.          |                                                         |
  989.          |     This window opened at absolute (12,15)              |
  990.          |            |                                            |
  991.          |            v                                            |
  992.          |            -----------------------                      |
  993.          |            |(1,1)          (1,30)|                      |
  994.          |            |                     |                      |
  995.          |            |                     |                      |
  996.          |            |(14,1)        (14,30)|                      |
  997.          |            -----------------------                      |
  998.          |(1,25)                                            (80,25)|
  999.          -----------------------------------------------------------
  1000.  
  1001.  
  1002.  
  1003.          Video Attributes
  1004.          ----------------
  1005.  
  1006.          With The C Window Library, a window can have an assortment
  1007.          of colors for text and background.  Each character that is
  1008.          displayed on the screen has its corresponding attribute
  1009.          byte.  The attribute byte is an 8-bit quantity that
  1010.          specifies a character's color, intensity, and blink status.
  1011.          The format of the attribute byte is as follows:
  1012.  
  1013.                              7  6  5  4  3  2  1  0
  1014.                            --------------------------
  1015.                            |B | bground |I|fground  |
  1016.                            |__|_________|_|_________|
  1017.  
  1018.  
  1019.          The B is the blink bit and the I is the intensity bit.  Bits
  1020.          0 thru 2 is a color code for the foreground (text) color.
  1021.          Bits 4 thru 6 determine the color code for the background
  1022.          (screen) color.
  1023.  
  1024.  
  1025.  
  1026.  
  1027.          Page 3          The C Window Library               Page 3
  1028.  
  1029.          If the blink bit is 1, then the character will blink.  If
  1030.          the intensity bit is on, the character will appear brighter
  1031.          than usual.  Some monitors cannot display high intensity
  1032.          characters, so the intensity bit may not change the
  1033.          characters brightness at all.
  1034.  
  1035.               Here is a list of color values along with the color
  1036.               they represent:
  1037.  
  1038.  
  1039.               Value   Color          Value   Color
  1040.  
  1041.                 0     Black           8     Gray
  1042.                 1     Blue            9     Light blue
  1043.                 2     Green          10     Light green
  1044.                 3     Cyan           11     Light cyan
  1045.                 4     Red            12     Light red
  1046.                 5     Magenta        13     Light magenta
  1047.                 6     Brown          14     Yellow
  1048.                 7     White          15     Intense white
  1049.  
  1050.          If the video system is a monochrome system, the color values
  1051.          specified above will give unpredictable results if not used
  1052.          carefully.  Monochrome systems also have an underline mode,
  1053.          that color systems (unless if you program the EGA or VGA
  1054.          adapters) cannot display.  Upcoming is a list of color
  1055.          values that should work on monochrome systems along with the
  1056.          type of display that will be produced:
  1057.  
  1058.  
  1059.             Display          Background      Foreground
  1060.  
  1061.             No display          0                 0
  1062.             Underline           0                 1
  1063.             Normal Video        0                 7
  1064.             Reverse Video       7                 0
  1065.  
  1066.          When programming a monochrome system, you can change the
  1067.          values of the colors not supported to black and white
  1068.          combinations supported on the monochrome system.  For
  1069.          example, you can change the light green color's value from
  1070.          10 to 7.  Now if light green is selected as a foreground
  1071.          color and the background color is black, you will have a
  1072.          normal video display on a monochrome system.
  1073.  
  1074.  
  1075.  
  1076.          Direct Screen Writes and BIOS Screen Updates
  1077.          --------------------------------------------
  1078.  
  1079.          By default, The C Window Library writes directly to screen
  1080.          memory.  This results in very fast screen output.  If you
  1081.          have ever wondered how commercial programs can display
  1082.          output so rapidly on the screen, direct screen writing is
  1083.  
  1084.  
  1085.  
  1086.  
  1087.          Page 4          The C Window Library               Page 4
  1088.  
  1089.          the major reason.  The disadvantage of writing directly to
  1090.          the screen is that it is ill- behaved with programs like
  1091.          Microsoft Windows or Quarterdeck's DesQView (although
  1092.          DesQView386 running on an 80386 machine is well behaved with
  1093.          direct screen writes).  Also on some color systems, the
  1094.          screen output is so fast that the video display produces
  1095.          "snow" on the screen.  However, The C Window Library will
  1096.          automatically detect whether "snow" should be checked when
  1097.          writing directly to the screen.  The old IBM Color Graphics
  1098.          Adapters suffer from this problem, but most other adapters
  1099.          including monochrome, Hercules, EGA, VGA, and newer CGA's do
  1100.          not suffer from this problem.  When checking for snow, the
  1101.          screen writes are not as fast as when there is no snow
  1102.          checking, but it is fast enough.
  1103.  
  1104.          The other method of updating the screen is by making a call
  1105.          to the video functions contained in the ROM BIOS.  BIOS
  1106.          stands for Basic Input Output System.  The BIOS provides
  1107.          routines that are needed for the operation of the computer.
  1108.          Some of these routines are video functions needed to write
  1109.          characters and attributes, move the cursor, and scroll
  1110.          portions of the screen.  Using the BIOS instead of writing
  1111.          directly to screen memory results in much slower screen
  1112.          updates, but will be compatible with programs like Microsoft
  1113.          Windows and DesQView.
  1114.  
  1115.          With The C Window Library, you are allowed to use either
  1116.          method.
  1117.  
  1118.  
  1119.  
  1120.  
  1121.          Video Paging
  1122.          ------------
  1123.  
  1124.          Since most video display adapters have enough memory to
  1125.          store more than one screen of characters,  these video
  1126.          adapters will support multiple video pages.  With multiple
  1127.          video pages, you can write to a hidden video page and then
  1128.          display the entire video page instantaneously. The only
  1129.          adapter that does not support video paging is the Monochrome
  1130.          Display Adapter (MDA).  All CGA's, EGA's and VGA's support
  1131.          multiple video pages.   The maximum number of pages a card
  1132.          will support is determined by the amount of RAM included in
  1133.          the video board, and the maximum number of characters that
  1134.          can be displayed on each page.  A list of the maximum number
  1135.          of video pages in each mode for each card is as follows:
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.          Page 5          The C Window Library               Page 5
  1148.  
  1149.          BIOS        Mode                               Max. #
  1150.          Mode #      Type           Adapter            of pages
  1151.          ----        ----           -------            --------
  1152.          0,1         Text        CGA, EGA, VGA             8
  1153.          2,3         Text        CGA,                      4
  1154.                                  EGA, VGA                  8
  1155.          7           Text        MDA, Hercules             1
  1156.                                  EGA, VGA                  8
  1157.  
  1158.          With The C Window Library, the video page displayed on the
  1159.          screen is called the visible page.  When creating a window,
  1160.          its page number is recorded.  When updating windows, the
  1161.          video page number where the window resides is used to direct
  1162.          the output to the appropriate video page.  There are also
  1163.          functions in The C Window Library that allow you to switch
  1164.          video pages.  With these routines, you can create very
  1165.          sophisticated user interfaces.  If you are using a clone
  1166.          Hercules Monochrome adapter, you may have access to more
  1167.          than one video page.  The original Hercules card has only
  1168.          one page of text memory.  The problem of accessing the other
  1169.          pages in the clone cards is that there is no universal way
  1170.          to determine how many pages that the card has.  If you are
  1171.          writing an application that targets a specific Hercules
  1172.          clone card, and you want to take advantage of the multiple
  1173.          pages, you can modify a global variable that contains the
  1174.          maximum number of available video pages, as well as the
  1175.          array that contains the segment:offset of each video page.
  1176.          Make sure you have the full documentation for the card, or
  1177.          know off-hand the number of pages and their addresses.
  1178.  
  1179.  
  1180.  
  1181.          Error Codes
  1182.          -----------
  1183.  
  1184.          With most of The C Window Library functions,
  1185.          window_error_code, which is a global integer variable is set
  1186.          to an error number when a function cannot be completed.
  1187.          Throughout this documentation, you are to assume that
  1188.          window_error_code is set to any error condition that is
  1189.          documented for each function.  The window_error_code
  1190.          variable IS NOT reset when a function has been completed
  1191.          successfully.  A list of error codes is as follows:
  1192.  
  1193.  
  1194.          Error Constant       Error Code           Definition
  1195.          --------------       ----------           ----------
  1196.  
  1197.          NO_HEAP_MEM               -1          Not enough memory to
  1198.                                                allocate from the
  1199.                                                heap.
  1200.  
  1201.          BAD_DISPLAY_PAGE          -2          Video Display page is
  1202.                                                invalid.
  1203.  
  1204.          INVALID_VIDEO_MODE        -3          Invalid video mode.
  1205.  
  1206.  
  1207.          Page 6          The C Window Library               Page 6
  1208.  
  1209.          INVALID_ROWS              -4          Invalid number of
  1210.                                                screen rows specified.
  1211.  
  1212.          BAD_WINDOW                -100        Window does not exist.
  1213.  
  1214.          BAD_WINDOW_SIZE           -101        Window dimensions are
  1215.                                                invalid.
  1216.  
  1217.          WINDOW_NOT_OPEN           -102        Window not open for
  1218.                                                read/write.
  1219.  
  1220.          WINDOW_BOUND              -103        Coordinates specified
  1221.                                                for window are out of
  1222.                                                bounds.
  1223.  
  1224.          MAX_WINDOW                -104        Maximum number of
  1225.                                                windows defined.
  1226.  
  1227.  
  1228.          WINDOW_INV_PARAM          -105        An invalid parameter
  1229.                                                was encountered in the
  1230.                                                function call.
  1231.  
  1232.          NO_INPUT_CHARS            -106        Trying to input a
  1233.                                                field of 0 characters.
  1234.  
  1235.          BAD_V_WINDOW              -200        The virtual window
  1236.                                                does not exist.
  1237.  
  1238.          END_V_WINDOW              -201        Internally used by The
  1239.                                                C Window Library.
  1240.  
  1241.          V_WINDOW_BOUND            -202        Coordinates specified
  1242.                                                for virtual window are
  1243.                                                out of bounds.
  1244.  
  1245.          MAX_V_WINDOW              -203        Maximum number of
  1246.                                                virtual windows
  1247.                                                defined.
  1248.          NO_ATTRIB                 -204        Virtual window does
  1249.                                                not have attributes.
  1250.  
  1251.          FILE_NO_EXIST             -300        File does not exist.
  1252.  
  1253.          FILE_CANT_CLOSE           -301        Cannot close file.
  1254.  
  1255.          FILE_CANT_OPEN            -302        Cannot open file.
  1256.  
  1257.          MENU_ENTRY_INVALID        -400        An invalid menu entry
  1258.                                                was specified.
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.          Page 7          The C Window Library               Page 7
  1268.  
  1269.  
  1270.          Window Manager
  1271.          --------------
  1272.  
  1273.          The window manager is the code in The C Window Library that
  1274.          handles window initialization, movement, coloring, and other
  1275.          functions that control window management.
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.          Page 8          The C Window Library               Page 8
  1328.  
  1329.                 MANDATORY FUNCTIONS AND HEADER FILES
  1330.                 ------------------------------------
  1331.  
  1332.          The only mandatory function is WindowInitializeSystem(),
  1333.          explained below.  The window.h header file must be included
  1334.          in any module that will call functions included in The C
  1335.          Window Library.
  1336.  
  1337.  
  1338.          WindowInitializeSystem()
  1339.          ------------------------
  1340.  
  1341.          This function MUST be called before any other function
  1342.          defined in The C Window Library.  This function also sets
  1343.          global variables, so it is also mandatory to call
  1344.          WindowInitializeSystem() before accessing any global
  1345.          variables defined by The C Window Library.
  1346.  
  1347.          WindowInitializeSystem() detects the type of video display
  1348.          used, the number of rows and columns that the screen
  1349.          currently displays, and initializes data structures and
  1350.          global variables.
  1351.  
  1352.          Example:
  1353.  
  1354.          #include "window.h"
  1355.  
  1356.          main()
  1357.          {
  1358.            WindowInitializeSystem();   /* Initialization function */
  1359.            /* Now it is safe to use C Window Library functions and
  1360.               global variables */
  1361.          }
  1362.  
  1363.          There is no return value for WindowInitializeSystem().
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.          Page 9          The C Window Library               Page 9
  1388.  
  1389.                           CREATING WINDOWS
  1390.                           ----------------
  1391.  
  1392.          We will now look how a window is created by defining a
  1393.          WINDOW, WPOINTER, and using the WindowSaveInitial() and
  1394.          WindowInitialize() function.
  1395.  
  1396.  
  1397.  
  1398.          The WINDOW structure and WPOINTER structure pointer
  1399.          ---------------------------------------------------
  1400.  
  1401.          When a window is created, the upper left hand column and
  1402.          row, the width, height, etc. must be recorded.  It would be
  1403.          very tedious if for every function call that acts on these
  1404.          windows we have to specify width, height, upper left hand
  1405.          row, etc. as function parameters.  The C Window Library
  1406.          conveniently has a structure called WINDOW, and its
  1407.          corresponding pointer called a WPOINTER to alleviate these
  1408.          problems.
  1409.  
  1410.          When a window is created, its characteristics are stored in
  1411.          a WINDOW structure, and most functions require that a pointer
  1412.          to this structure be passed.  This pointer is called a
  1413.          WPOINTER.  By only referring to the WPOINTER, argument lists
  1414.          to functions become much shorter.
  1415.  
  1416.  
  1417.  
  1418.  
  1419.          WindowSaveInitial()
  1420.          -------------------
  1421.  
  1422.          The WindowSaveInitial() function saves the base screen as a
  1423.          window.  This MUST be called prior to creating any windows.
  1424.          Here is a prototype:
  1425.  
  1426.               int WindowSaveInitial(int page)
  1427.  
  1428.          The page argument is the video page of the base screen to
  1429.          save.  If you are creating windows that will be manipulated
  1430.          on video page 0, you must call WindowSaveInitial() with 0 as
  1431.          the argument:
  1432.  
  1433.          #include "window.h"
  1434.  
  1435.          main()
  1436.          {
  1437.            WindowInitializeSystem(); /* Initialize global variables */
  1438.            WindowSaveInitial(0); /* Save video page 0's base screen */
  1439.          }
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.          Page 10          The C Window Library               Page 10
  1448.  
  1449.          In most applications, the initial screen page is page 0.
  1450.          However, it is safer to use the global variable
  1451.          active_video_page (explained in the IMPORTANT GLOBAL
  1452.          VARIABLES section) to determine the page.  If you are
  1453.          changing video pages in an application, the new page has
  1454.          to be initialized with WindowSaveInitial() so that the
  1455.          window manager updates the screen properly when moving
  1456.          windows, hiding windows, etc.  This function must be called
  1457.          only once in an application for each screen page desired.
  1458.  
  1459.          If there is no error, WindowSaveInitial() returns NO_ERROR.
  1460.          If there is an error, WindowSaveInitial() returns the
  1461.          following values:
  1462.  
  1463.          BAD_DISPLAY_PAGE if the page desired does not exist, or was
  1464.          not detected by The C Window Library.
  1465.  
  1466.          NO_HEAP_MEM if there is no memory to save the initial screen.
  1467.  
  1468.          MAX_WINDOW if the maximum number of windows has already been
  1469.          defined.
  1470.  
  1471.  
  1472.  
  1473.  
  1474.          WindowInitialize()
  1475.          ------------------
  1476.  
  1477.          The next function is WindowInitialize().  This function sets
  1478.          up a window with the position on the screen to place the
  1479.          window, width, height, colors, and box type.  If successful,
  1480.          this function returns a new WPOINTER.  Here is an example:
  1481.  
  1482.          #include "window.h"
  1483.          #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1484.  
  1485.          WPOINTER w;
  1486.          main()
  1487.          {
  1488.            WindowInitializeSystem();
  1489.            WindowSaveInitial(0);
  1490.            w = WindowInitialize(BORDER,1,1,30,15,NORM,NORM,SINGLEBOX);
  1491.            ...
  1492.          }
  1493.  
  1494.          In the above example, we have defined a variable w as having
  1495.          a WPOINTER type.  This variable will ultimately point to a
  1496.          valid WINDOW structure.  The first argument to
  1497.          WindowInitialize() is a constant called BORDER.  This tells
  1498.          the window manager that the window desired is going to have
  1499.          a border.  If no border was desired, the constant would be
  1500.          NOBORDER. The second and third arguments tells the window
  1501.          manager the row and column of the screen where the upper
  1502.          left corner of the window will be located.  Since the upper
  1503.          left corner of the screen is row 1, column 1, the upper left
  1504.          hand corner of the window will be placed at the upper left
  1505.  
  1506.  
  1507.          Page 11          The C Window Library               Page 11
  1508.  
  1509.          corner of the video screen.  The fourth and fifth argument
  1510.          denotes the width and the height of the window.  DO NOT
  1511.          INCLUDE THE BORDERS (if any) TO DETERMINE THE WIDTH AND
  1512.          HEIGHT OF THE WINDOW.  Our window will have a width of 30
  1513.          characters and a height of 15 characters.  The sixth and
  1514.          seventh arguments are the video attributes of the inside of
  1515.          the window and the border respectively.
  1516.  
  1517.          The last argument tells us what type of border the window
  1518.          will have.  We use the constant SINGLEBOX to tell the window
  1519.          manager that we want a window with a border made up of
  1520.          single lines.
  1521.  
  1522.          If there is no error, WindowInitialize() returns a valid
  1523.          WPOINTER.
  1524.  
  1525.          If there is an error, WindowInitialize() returns a
  1526.          WIN_NULL_PTR (a null window pointer) and sets
  1527.          window_error_code to one of the following values:
  1528.  
  1529.          NO_HEAP_MEM if there is not enough memory to allocate for
  1530.          the window structure.
  1531.  
  1532.          BAD_WINDOW_SIZE if the dimensions for the window are too
  1533.          large for the physical screen.
  1534.  
  1535.          MAX_WINDOW if there are > 254 windows defined.
  1536.  
  1537.          Even though there is a structure type called WINDOW, you
  1538.          should always use the pointer to the structure (WPOINTER)
  1539.          rather than the WINDOW structure itself.
  1540.  
  1541.  
  1542.  
  1543.          CREATE_VIDEO_ATTRIBUTE() macro
  1544.          ------------------------------
  1545.  
  1546.          Please note the use of the macro CREATE_VIDEO_ATTRIBUTE() in
  1547.          the previous example to create an integer representing the
  1548.          foreground and background colors.  This macro uses the first
  1549.          argument as the background color, and the second argument is
  1550.          the foreground color.  In the above example we have a
  1551.          constant called NORM which uses CREATE_VIDEO_ATTRIBUTE() to
  1552.          create a black background and a white foreground color
  1553.          combination.
  1554.  
  1555.  
  1556.  
  1557.          Box types
  1558.          ---------
  1559.          For ease of use, There are predefined constants found in the
  1560.          vidsys.h header file that contains definitions of common
  1561.          border types.  These constants are as follows:
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.          Page 12          The C Window Library               Page 12
  1568.  
  1569.          DOUBLEBOX -- defines border characters for double box
  1570.                       windows.
  1571.  
  1572.          SINGLEBOX -- defines border characters for single box
  1573.                       windows.
  1574.  
  1575.          MIXEDBOX1 -- defines double lines for top and bottom and
  1576.                       single lines on the sides.
  1577.  
  1578.          MIXEDBOX2 -- defines single lines for top and bottom and
  1579.                       double lines on the sides.
  1580.  
  1581.          HATCHBOX1 -- defines a 'dotty' box.
  1582.  
  1583.          HATCHBOX2 -- Another 'dotty' box.
  1584.  
  1585.          HATCHBOX3 -- Yet another 'dotty' box.
  1586.  
  1587.          SOLIDBOX1 -- defines a box of solid characters.
  1588.  
  1589.          SOLIDBOX2 -- defines another box of different solid
  1590.                       characters.
  1591.  
  1592.          BLANKBOX  -- defines a box with a blank border.  When using
  1593.                       these characters, do not get confused with a
  1594.                       blank border.
  1595.  
  1596.          DOTTEDLINE -- defines a box with dotted lines.
  1597.  
  1598.  
  1599.  
  1600.          Although there are predefined border types in The C Window
  1601.          Library, you can define your own types.  The window border
  1602.          characters are represented by an 8 byte character string.
  1603.          Each character in this string refers to a border character
  1604.          to be used in drawing the window border.  A list of what
  1605.          each position in the string stands for is as follows:
  1606.  
  1607.          position                Representation
  1608.          --------           ---------------------------
  1609.             0               Upper left corner character.
  1610.             1               Top line character.
  1611.             2               Upper right corner character.
  1612.             3               Left side character.
  1613.             4               Right side character.
  1614.             5               Bottom left corner character.
  1615.             6               Bottom line character.
  1616.             7               Bottom right corner character.
  1617.  
  1618.  
  1619.          This character string is sent to the window functions that
  1620.          call for a string of box drawing characters.  For example,
  1621.          you can create your own customized set of characters with
  1622.          something like this:
  1623.  
  1624.          #define MYBOXCHARS  "+-+||+-+"
  1625.  
  1626.  
  1627.          Page 13          The C Window Library               Page 13
  1628.  
  1629.          MYBOXCHARS is a literal string of box drawing characters.
  1630.          Using the rules of box drawing characters defined above, the
  1631.          upper left hand corner of the box is the plus sign, the top
  1632.          line is the hyphen, the upper right and corner is the plus
  1633.          sign, the left side is a pipe character, as is the right
  1634.          side, and the bottom part of the box is defined the same as
  1635.          the upper part.  Then you would use it in a call to any
  1636.          function that asks for a box drawing string like this:
  1637.  
  1638.  
  1639.                w = WindowInitialize(BORDER, ... ,MYBOXCHARS);
  1640.  
  1641.  
  1642.          The '... ' are the other arguments that you would normally
  1643.          put for the WindowInitialize() function.
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.          Page 14          The C Window Library               Page 14
  1688.  
  1689.                OPENING WINDOWS FOR READING AND WRITING
  1690.                ---------------------------------------
  1691.  
  1692.          The next step is to allocate memory for the window's text
  1693.          buffer.  This will allow writing and reading characters to
  1694.          the window even though it is not visible.
  1695.  
  1696.  
  1697.  
  1698.          WindowOpen()
  1699.          ------------
  1700.  
  1701.          The WindowOpen() function is used to allocate memory for the
  1702.          window's text buffer.  This function MUST be called if you
  1703.          are going to do many of the window functions.  Here is the
  1704.          previous example with the WindowOpen() call:
  1705.  
  1706.          #include "window.h"
  1707.          #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1708.  
  1709.          WPOINTER w;
  1710.          main()
  1711.          {
  1712.            WindowInitializeSystem();
  1713.            WindowSaveInitial(0);
  1714.            w = WindowInitialize(BORDER,1,1,20,15,NORM,NORM,SINGLEBOX);
  1715.            WindowOpen(w);
  1716.               ...
  1717.          }
  1718.  
  1719.          The WindowOpen() function does not display the window.  The
  1720.          argument tells the window manager what window to open.  In
  1721.          this case we want to open our new window, w.  The window
  1722.          buffer is cleared to spaces using the window's text
  1723.          attribute, and the border (if there is a border) is drawn
  1724.          internally.  When a window is opened with WindowOpen(), you
  1725.          can then write or read characters to a window, move, scroll,
  1726.          etc.  almost any function that you can do with a visible
  1727.          window.
  1728.  
  1729.          If there is no error, WindowOpen() returns NO_ERROR.
  1730.          If there is an error, WindowOpen() returns one of the
  1731.          following:
  1732.  
  1733.          1) NO_HEAP_MEM if there is not enough memory to allocate for
  1734.             the window buffer.
  1735.  
  1736.          2) BAD_WINDOW if the window does not exist.
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.          Page 15          The C Window Library               Page 15
  1748.  
  1749.                          DISPLAYING WINDOWS
  1750.                          ------------------
  1751.  
  1752.          Now we will display the window we created in the previous
  1753.          example.
  1754.  
  1755.  
  1756.          The WindowDisplay() function and Explosion Effects
  1757.          --------------------------------------------------
  1758.  
  1759.          The WindowDisplay() function displays a window.  Here is the
  1760.          previous example with WindowDisplay() added to it:
  1761.  
  1762.          #include "window.h"
  1763.          #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1764.  
  1765.          WPOINTER w;
  1766.          main()
  1767.          {
  1768.            WindowInitializeSystem();
  1769.            WindowSaveInitial(0);
  1770.            w = WindowInitialize(BORDER,1,1,20,15,NORM,NORM,SINGLEBOX);
  1771.            WindowOpen(w);
  1772.            WindowDisplay(w,1,NOEFFECT);
  1773.            ...
  1774.          }
  1775.  
  1776.          The first argument to WindowDisplay() is the window to
  1777.          display, in our case, w is the window.  The second argument
  1778.          is the rank order of the window.  Since the rank order we
  1779.          desire is 1, this window will lie on top of all windows,
  1780.          unless another window is opened with a rank of 1.  Remember,
  1781.          any window with a rank number n will have windows with rank
  1782.          n-1, n-2,...,1 to be displayed on top of it.  You can change
  1783.          the rank order of a window at any time by calling
  1784.          WindowDisplay() with a different rank number.
  1785.  
  1786.          The third argument to WindowDisplay() is the explosion
  1787.          effect of the window when it is displayed.  There are
  1788.          currently 12 ways to explode a window on the screen,
  1789.          numbered from 0 thru 11.  Here is an overview of each
  1790.          effect:
  1791.  
  1792.  
  1793.          Defined Constant        Value            Effect
  1794.          ----------------        -----            ------
  1795.  
  1796.             NOEFFECT               0          ┌─────────────┐
  1797.                                               │             │
  1798.                                               │             │
  1799.                                               │             │
  1800.                                               │             │
  1801.                                               │             │
  1802.                                               │             │
  1803.                                               │             │
  1804.                                               └─────────────┘
  1805.  
  1806.  
  1807.          Page 16          The C Window Library               Page 16
  1808.  
  1809.  
  1810.             EXPLODE                1       ┌─────────────────┐
  1811.                                            │        ^        │
  1812.                                            │        |        │
  1813.                                            │        |        │
  1814.                                            │<--           -->│
  1815.                                            │                 │
  1816.                                            │        |        │
  1817.                                            │        |        │
  1818.                                            │        v        │
  1819.                                            └─────────────────┘
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.             CONTRACT               2       ┌─────────────────┐
  1826.                                            │        |        │
  1827.                                            │        |        │
  1828.                                            │        v        │
  1829.                                            │-->           <--│
  1830.                                            │        ^        │
  1831.                                            │        |        │
  1832.                                            │        |        │
  1833.                                            └─────────────────┘
  1834.  
  1835.  
  1836.             BRICKS                 3        ┌────────────────┐
  1837.                                             │█     █    █   █│
  1838.                                             │ █              │
  1839.                                             │     █     █  █ │
  1840.                                             │        █       │
  1841.                                             │  █  █    █   █ │
  1842.                                             │█        █      │
  1843.                                             └────────────────┘
  1844.  
  1845.  
  1846.  
  1847.  
  1848.                                                      ^
  1849.             MIDDLEROWOUT           4                 |
  1850.                                              ┌───────────────┐
  1851.                                              └───────────────┘
  1852.                                                      |
  1853.                                                      v
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.             TOPBOTTOMIN            5         ┌───────────────┐
  1862.                                              └───────────────┘
  1863.                                                      |
  1864.                                                      v
  1865.  
  1866.  
  1867.          Page 17          The C Window Library               Page 17
  1868.  
  1869.  
  1870.                                                      ^
  1871.                                                      |
  1872.                                              ┌───────────────┐
  1873.                                              └───────────────┘
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.             TOPDOWN                6         ┌───────────────┐
  1882.                                              └───────────────┘
  1883.                                                      |
  1884.                                                      v
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.                                                      ^
  1892.             BOTTOMUP               7                 |
  1893.                                              ┌───────────────┐
  1894.                                              └───────────────┘
  1895.  
  1896.  
  1897.  
  1898.  
  1899.             MIDDLECOLOUT           8                ┌┐
  1900.                                                     ││
  1901.                                                     ││
  1902.                                                     ││
  1903.                                                   <-││->
  1904.                                                     ││
  1905.                                                     ││
  1906.                                                     ││
  1907.                                                     └┘
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.             LEFTRIGHTIN            9              ┌┐      ┌┐
  1916.                                                   ││      ││
  1917.                                                   ││      ││
  1918.                                                   ││      ││
  1919.                                                   ││->  <-││
  1920.                                                   ││      ││
  1921.                                                   ││      ││
  1922.                                                   ││      ││
  1923.                                                   └┘      └┘
  1924.  
  1925.  
  1926.  
  1927.          Page 18          The C Window Library               Page 18
  1928.  
  1929.  
  1930.  
  1931.  
  1932.  
  1933.             LEFTTORIGHT            10             ┌┐
  1934.                                                   ││
  1935.                                                   ││
  1936.                                                   ││
  1937.                                                   ││->
  1938.                                                   ││
  1939.                                                   ││
  1940.                                                   ││
  1941.                                                   ││
  1942.                                                   └┘
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.             RIGHTTOLEFT            11             ┌┐
  1949.                                                   ││
  1950.                                                   ││
  1951.                                                   ││
  1952.                                                 <-││
  1953.                                                   ││
  1954.                                                   ││
  1955.                                                   ││
  1956.                                                   ││
  1957.                                                   └┘
  1958.  
  1959.  
  1960.          If there is no error, WindowDisplay() will return NO_ERROR.
  1961.          If there is an error, WindowDisplay() will return one of the
  1962.          following:
  1963.  
  1964.          BAD_WINDOW if the window does not exist.
  1965.  
  1966.          WINDOW_NOT_OPEN if the window was not open with WindowOpen().
  1967.  
  1968.  
  1969.  
  1970.          Displaying Multiple Windows
  1971.          ---------------------------
  1972.  
  1973.          If you are creating multiple windows you can change the rank
  1974.          of the window by calling WindowDisplay() with a different
  1975.          rank number.  Here is an example:
  1976.  
  1977.  
  1978.  
  1979.          #include "window.h"
  1980.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1981.          #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.          Page 19          The C Window Library               Page 19
  1988.  
  1989.          #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  1990.          #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  1991.  
  1992.          main()
  1993.          {
  1994.            int i;
  1995.            WPOINTER w1,w2,w3; /* pointers to a window structures */
  1996.            WindowInitializeSystem();
  1997.            WindowSaveInitial(0);
  1998.            w1 = WindowInitialize(BORDER,1,1,30,15,BLUEONBLACK,NORM,
  1999.                                  SINGLEBOX);
  2000.  
  2001.            /* define second window */
  2002.            w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,
  2003.                                  DOUBLEBOX);
  2004.  
  2005.            /* define third window */
  2006.            w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,
  2007.                                  SINGLEBOX);
  2008.  
  2009.            WindowOpen(w1);      /* make window 1 ok to write */
  2010.            WindowOpen(w2);      /* make window 2 ok to write */
  2011.            WindowOpen(w3);      /* make window 3 ok to write */
  2012.  
  2013.            WindowDisplay(w1,1,NOEFFECT);
  2014.            WindowDisplay(w2,2,NOEFFECT);
  2015.            WindowDisplay(w3,3,NOEFFECT);
  2016.  
  2017.            GET_KEY();
  2018.            WindowDisplay(w2,1,NOEFFECT);
  2019.            GET_KEY();
  2020.            WindowDisplay(w3,1,NOEFFECT);
  2021.            GET_KEY();
  2022.            WindowDisplay(w1,1,NOEFFECT);
  2023.            GET_KEY();
  2024.          }
  2025.  
  2026.  
  2027.          In the above program, w1, w2, and w3 are displayed with rank
  2028.          numbers of 1, 2, and 3, respectively.  The ordering means
  2029.          that w1 will overlay w2, and w2 will overlay w3.
  2030.  
  2031.          Note that after the windows w1, w2, and w3 are initially
  2032.          displayed, they are redisplayed by making another call to
  2033.          WindowDisplay().  You can redisplay a window and change its
  2034.          rank by calling the WindowDisplay() function again.  For
  2035.          example, w2 is redisplayed with a rank of 1.  This promotes
  2036.          w2 to the top of the stack of displayed windows, and demotes
  2037.          w1 with a rank of 2.  Each and every window has a unique
  2038.          rank number.  The window manager keeps track of conflicts in
  2039.          rank numbers, and adjusts the data structures involved in
  2040.          maintaining the windows in working order.  Therefore, there
  2041.          is really no need for you to remember whether a rank number
  2042.          is used or not.
  2043.  
  2044.          The macro GET_KEY() pauses the program until you press a key.
  2045.  
  2046.  
  2047.          Page 20          The C Window Library               Page 20
  2048.  
  2049.                            CLOSING WINDOWS
  2050.                            ---------------
  2051.  
  2052.          In this section, we will discuss closing windows with and
  2053.          without destroying the window pointer.
  2054.  
  2055.  
  2056.  
  2057.          WindowClose()
  2058.          -------------
  2059.  
  2060.          The WindowClose() function hides a window from the screen
  2061.          and deallocates any memory that was allocated by the
  2062.          WindowOpen() function described in the previous section.
  2063.          This DOES NOT destroy the window pointer (WPOINTER), however
  2064.          you must call WindowOpen() again if you want to use this
  2065.          window again for most other window functions.  Here is the
  2066.          prototype:
  2067.  
  2068.  
  2069.                    int WindowClose(WPOINTER w, int effect)
  2070.  
  2071.          The first argument is the window.  The second argument is
  2072.          the special effect to use when closing the window.  This
  2073.          argument is only meaningful if the window is visible.  For a
  2074.          list of effects refer back to the DISPLAYING WINDOWS
  2075.          section.  This function can be used if you are short of
  2076.          memory, but you do not want to destroy the WPOINTER.
  2077.  
  2078.  
  2079.  
  2080.          Example:
  2081.  
  2082.  
  2083.           #include "window.h"
  2084.           #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2085.           #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)
  2086.           #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  2087.           #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  2088.  
  2089.           main()
  2090.           {
  2091.             int i;
  2092.             WPOINTER w1,w2,w3;
  2093.             WindowInitializeSystem();
  2094.             WindowSaveInitial(0);
  2095.             w1 = WindowInitialize(BORDER,1,1,30,15,BLUEONBLACK,NORM,
  2096.                                   SINGLEBOX);
  2097.  
  2098.             /* define second window */
  2099.             w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,
  2100.                                   DOUBLEBOX);
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.          Page 21          The C Window Library               Page 21
  2108.  
  2109.             /* define third window */
  2110.             w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,
  2111.                                   SINGLEBOX);
  2112.  
  2113.  
  2114.  
  2115.             WindowOpen(w1);      /* make window 1 ok to write */
  2116.  
  2117.             WindowOpen(w2);      /* make window 2 ok to write */
  2118.  
  2119.             WindowOpen(w3);      /* make window 3 ok to write */
  2120.  
  2121.             WindowDisplay(w1,1,NOEFFECT);
  2122.             WindowDisplay(w2,2,NOEFFECT);
  2123.             WindowDisplay(w3,3,NOEFFECT);
  2124.  
  2125.             GET_KEY();
  2126.             WindowDisplay(w2,1,NOEFFECT);
  2127.             GET_KEY();
  2128.             WindowDisplay(w3,1,NOEFFECT);
  2129.             GET_KEY();
  2130.             WindowDisplay(w1,1,NOEFFECT);
  2131.             GET_KEY();
  2132.             WindowClose(w2,NOEFFECT);
  2133.             GET_KEY();
  2134.             WindowClose(w3,NOEFFECT);
  2135.             GET_KEY();
  2136.             WindowClose(w1,NOEFFECT);
  2137.           }
  2138.  
  2139.  
  2140.          The example above calls WindowClose() on all three windows.
  2141.  
  2142.          If there are no errors, WindowClose() returns NO_ERROR.
  2143.          If there are errors, WindowClose() returns the following
  2144.          value:
  2145.  
  2146.          BAD_WINDOW if the window w does not exist.
  2147.  
  2148.  
  2149.          WindowFree()
  2150.          ------------
  2151.  
  2152.          The WindowFree() function acts just like the WindowClose()
  2153.          function except that the WPOINTER is also deallocated.  This
  2154.          means that the WPOINTER cannot be used anymore unless it is
  2155.          initialized again using WindowInitialize(), or is assigned
  2156.          to another valid WPOINTER.  Here is the prototype:
  2157.  
  2158.                       int WindowFree(WPOINTER w, int effect)
  2159.  
  2160.          Refer to WindowClose() for definitions of arguments and
  2161.          return values.
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.          Page 22          The C Window Library               Page 22
  2168.  
  2169.          WindowCloseAll()
  2170.          ----------------
  2171.  
  2172.          The WindowCloseAll() function acts just like WindowClose()
  2173.          function except that all windows are closed on a desired
  2174.          video page.  Here is the prototype:
  2175.  
  2176.                       int WindowCloseAll(int page, int effect)
  2177.  
  2178.          The page argument is the video page of where the windows are
  2179.          located.  Remember that The C Window Library allows
  2180.          displaying windows on video pages other than page 0 (default
  2181.          page).  The effect argument is the special effect to use
  2182.          when closing the window.  Refer to DISPLAYING WINDOWS for
  2183.          the list of special effects.
  2184.  
  2185.          Example:
  2186.  
  2187.          #include "window.h"
  2188.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2189.          #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)
  2190.          #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  2191.          #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  2192.  
  2193.          main()
  2194.          {
  2195.            int i;
  2196.            WPOINTER w1,w2,w3;
  2197.            WindowInitializeSystem();
  2198.            WindowSaveInitial(0);
  2199.            w1 = WindowInitialize(BORDER,1,1,30,15,BLUEONBLACK,NORM,
  2200.                                  SINGLEBOX);
  2201.  
  2202.            /* define second window */
  2203.            w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,
  2204.                                  DOUBLEBOX);
  2205.  
  2206.            /* define third window */
  2207.            w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,
  2208.                                  SINGLEBOX);
  2209.  
  2210.            WindowOpen(w1);      /* make window 1 ok to write */
  2211.            WindowOpen(w2);      /* make window 2 ok to write */
  2212.            WindowOpen(w3);      /* make window 3 ok to write */
  2213.            WindowDisplay(w1,1,NOEFFECT);
  2214.            WindowDisplay(w2,2,NOEFFECT);
  2215.            WindowDisplay(w3,3,NOEFFECT);
  2216.            WindowCloseAll(0,NOEFFECT);  /* close all the windows */
  2217.          }
  2218.  
  2219.  
  2220.          The example above calls WindowCloseAll() to close all three
  2221.          windows.
  2222.  
  2223.          Refer to WindowClose() for return values.
  2224.  
  2225.  
  2226.  
  2227.          Page 23          The C Window Library               Page 23
  2228.  
  2229.          WindowFreeAll()
  2230.          ---------------
  2231.  
  2232.          The WindowFreeAll() function acts just like WindowClose()
  2233.          function except that all windows are freed on a desired video
  2234.          page.  Here is the prototype:
  2235.  
  2236.                   int WindowFreeAll(int page, int effect)
  2237.  
  2238.          The page argument is the video page of where the windows are
  2239.          located.  Remember that The C Window Library allows
  2240.          displaying windows on video pages other than page 0 (default
  2241.          page).  The effect argument is the special effect to use when
  2242.          closing the window.  Refer to DISPLAYING WINDOWS for the list
  2243.          of special effects.
  2244.  
  2245.          Refer to WindowCloseAll() for return values.
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.          Page 24          The C Window Library               Page 24
  2288.  
  2289.                    CENTERING WINDOWS ON THE SCREEN
  2290.                    -------------------------------
  2291.  
  2292.           The C Window Library allows easy centering of windows on
  2293.           the screen.
  2294.  
  2295.  
  2296.          WindowCenter()
  2297.          --------------
  2298.  
  2299.  
  2300.          The WindowCenter() function centers a window on the screen
  2301.          vertically, horizontally, or both.  Here is the prototype:
  2302.  
  2303.               int WindowCenter(WPOINTER w, int option)
  2304.  
  2305.          The first argument is the window to center, and the second
  2306.          argument tells whether to center the window horizontally,
  2307.          vertically, or both.  The options argument must be one of
  2308.          the following:
  2309.  
  2310.                 Value of
  2311.                 options                    Type of centering
  2312.                 -------                    -----------------
  2313.  
  2314.               VERTCENTER                       vertical
  2315.  
  2316.               HORIZCENTER                     horizontal
  2317.  
  2318.               VERTCENTER | HORIZCENTER     both horizontal and
  2319.                                            vertical
  2320.  
  2321.  
  2322.          Note the bitwise OR (|) between the constants VERTCENTER and
  2323.          HORIZCENTER for both horizontal and vertical centering.
  2324.          This function can be used on hidden windows and windows that
  2325.          have not been opened with WindowOpen().
  2326.  
  2327.  
  2328.          Example:
  2329.  
  2330.  
  2331.          #include "window.h"
  2332.  
  2333.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2334.  
  2335.          WPOINTER w;
  2336.  
  2337.          main()
  2338.          {
  2339.            WindowInitializeSystem();
  2340.            WindowSaveInitial(0);
  2341.            w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2342.            WindowOpen(w);
  2343.            WindowDisplay(w,1,NOEFFECT);
  2344.            GET_KEY();
  2345.  
  2346.  
  2347.          Page 25          The C Window Library               Page 25
  2348.  
  2349.            WindowCenter(w,VERTCENTER);  /* center vertically */
  2350.            GET_KEY();
  2351.            WindowMove(w,1,1);
  2352.            GET_KEY();
  2353.            WindowCenter(w,HORIZCENTER); /* center horizontally */
  2354.            GET_KEY();
  2355.            WindowMove(w,1,1);
  2356.            GET_KEY();
  2357.            WindowCenter(w,VERTCENTER | HORIZCENTER); /* center both
  2358.                                           horizontal and vertical */
  2359.            GET_KEY();
  2360.            WindowFree(w,NOEFFECT);
  2361.          }
  2362.  
  2363.  
  2364.          If there are no errors, WindowCenter() returns NO_ERROR.
  2365.          If there is an error, the following value is returned:
  2366.  
  2367.             BAD_WINDOW if the window does not exist.
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.  
  2384.  
  2385.  
  2386.  
  2387.  
  2388.  
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.          Page 26          The C Window Library               Page 26
  2408.  
  2409.                    CHANGING WINDOW CHARACTERISTICS
  2410.                    -------------------------------
  2411.  
  2412.          In this section, we will discuss changing the window
  2413.          attributes, border style, and the window's height and width.
  2414.  
  2415.  
  2416.          WindowChangeTextAttribute()
  2417.          ---------------------------
  2418.  
  2419.  
  2420.          This function changes the attribute of the text portion of
  2421.          the window.  The text portion is the inside of the window.
  2422.          Here is a prototype:
  2423.  
  2424.             int WindowChangeTextAttribute(WPOINTER w, int color)
  2425.  
  2426.          where w is the WPOINTER to change the text attribute, and
  2427.          color is the new color.  You can use the
  2428.          CREATE_VIDEO_ATTRIBUTE() macro to define the color.
  2429.  
  2430.          Example:
  2431.  
  2432.          #include "window.h"
  2433.  
  2434.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2435.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2436.  
  2437.          WPOINTER w;
  2438.  
  2439.          main()
  2440.          {
  2441.            WindowInitializeSystem();
  2442.            WindowSaveInitial(0);
  2443.            w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2444.            WindowOpen(w);
  2445.            WindowDisplay(w,1,NOEFFECT);
  2446.            GET_KEY();
  2447.            WindowChangeTextAttribute(w,REVERSE);
  2448.          }
  2449.  
  2450.          If there is no error, WindowChangeTextAttribute() returns
  2451.          NO_ERROR.
  2452.  
  2453.          If there is an error, the following value is
  2454.          returned:
  2455.  
  2456.             BAD_WINDOW if the window does not exist.
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462.  
  2463.  
  2464.  
  2465.  
  2466.  
  2467.          Page 27          The C Window Library               Page 27
  2468.  
  2469.          WindowChangeBorderAttribute()
  2470.          -----------------------------
  2471.  
  2472.          This function changes the video attribute of the border of
  2473.          the window.  If the window does not have a border, nothing is
  2474.          changed.  Here is a prototype:
  2475.  
  2476.            int WindowChangeBorderAttribute(WPOINTER w, int color)
  2477.  
  2478.          where w is the WPOINTER to change the border attribute, and
  2479.          color is the new color.  You can use the
  2480.          CREATE_VIDEO_ATTRIBUTE() macro to define the color.
  2481.  
  2482.  
  2483.  
  2484.          Example:
  2485.  
  2486.  
  2487.          #include "window.h"
  2488.  
  2489.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2490.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2491.  
  2492.          WPOINTER w;
  2493.  
  2494.          main()
  2495.          {
  2496.            WindowInitializeSystem();
  2497.            WindowSaveInitial(0);
  2498.            w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2499.            WindowOpen(w);
  2500.            WindowDisplay(w,1,NOEFFECT);
  2501.            GET_KEY();
  2502.            WindowChangeBorderAttribute(w,REVERSE);
  2503.          }
  2504.  
  2505.          If there is no error, or if the window does not have a
  2506.          border, WindowChangeBorderAttribute() returns NO_ERROR.
  2507.  
  2508.          If there is an error, WindowChangeBorderAttribute() returns
  2509.          the following value:
  2510.  
  2511.             BAD_WINDOW if the WPOINTER w does not exist.
  2512.  
  2513.  
  2514.  
  2515.  
  2516.          WindowDrawBorder()
  2517.          ------------------
  2518.  
  2519.          You can also change the border type, or draw a border on an
  2520.          unbordered window by calling the WindowDrawBorder()
  2521.          function.
  2522.  
  2523.  
  2524.  
  2525.  
  2526.  
  2527.          Page 28          The C Window Library               Page 28
  2528.  
  2529.          Here is a prototype:
  2530.  
  2531.              int WindowDrawBorder(WPOINTER w, char *box)
  2532.  
  2533.          The first argument is the window we want to change the
  2534.          border of.  The second argument is a string of border
  2535.          characters.  This string denotes the type of border that the
  2536.          window should now have.  In the example given below, w is
  2537.          initialized with a SINGLEBOX border, but WindowDrawBorder()
  2538.          changes this to a DOUBLEBOX.
  2539.  
  2540.          The WindowDrawBorder() function is also used to draw borders
  2541.          on borderless windows.  When drawing borders on a NOBORDER
  2542.          window, the window must not have any of its sides touching
  2543.          the edges of the physical screen.  In other words, the
  2544.          window must "have room" for a border to be drawn.  If there
  2545.          is no room to draw the border, there is no change to the
  2546.          window.
  2547.  
  2548.          Example:
  2549.  
  2550.  
  2551.          #include "window.h"
  2552.  
  2553.          #define REVERSE   CREATE_VIDEO_ATTRIBUTE(white,black)
  2554.  
  2555.          WPOINTER w;
  2556.  
  2557.          main()
  2558.          {
  2559.            WindowInitializeSystem();
  2560.            WindowSaveInitial(0);
  2561.            w = WindowInitialize(NOBORDER,2,2,10,10,REVERSE,REVERSE,
  2562.                                 SINGLEBOX);
  2563.            WindowOpen(w);
  2564.            WindowDisplay(w,1,NOEFFECT);
  2565.            GET_KEY();
  2566.            WindowDrawBorder(w,DOUBLEBOX);  /* Draws a double box
  2567.                                            around NOBORDER window */
  2568.          }
  2569.  
  2570.  
  2571.          If there is no error, WindowDrawBorder() returns NO_ERROR.
  2572.          If there is an error, WindowDrawBorder() returns one of the
  2573.          following values:
  2574.  
  2575.          BAD_WINDOW if the window w does not exist.
  2576.  
  2577.          NO_HEAP_MEM if there is not enough memory to allocate for
  2578.          temporary buffer.
  2579.  
  2580.  
  2581.  
  2582.  
  2583.  
  2584.  
  2585.  
  2586.  
  2587.          Page 29          The C Window Library               Page 29
  2588.  
  2589.          WindowRemoveBorder()
  2590.          --------------------
  2591.  
  2592.          This function removes a border from a bordered window.  Here
  2593.          is the prototype:
  2594.  
  2595.               int WindowRemoveBorder(WPOINTER w)
  2596.  
  2597.          If the window does not have a border, nothing is changed.
  2598.  
  2599.          Example:
  2600.  
  2601.          #include "window.h"
  2602.          #define REVERSE   CREATE_VIDEO_ATTRIBUTE(white,black)
  2603.  
  2604.          WPOINTER w;
  2605.  
  2606.          main()
  2607.          {
  2608.            WindowInitializeSystem();
  2609.            WindowSaveInitial(0);
  2610.            w = WindowInitialize(BORDER,1,1,10,10,REVERSE,REVERSE,
  2611.                                 SINGLEBOX);
  2612.            WindowOpen(w);
  2613.            WindowDisplay(w,1,NOEFFECT);
  2614.            GET_KEY();
  2615.            WindowRemoveBorder(w);  /* Removes the double box around
  2616.                                       BORDERed window */
  2617.          }
  2618.  
  2619.          If there is no error, WindowRemoveBorder() returns NO_ERROR.
  2620.          If there is an error, WindowRemoveBorder returns one of the
  2621.          following values:
  2622.  
  2623.            BAD_WINDOW if the window w does not exist.
  2624.  
  2625.            NO_HEAP_MEM if there is not enough memory to allocate for
  2626.            temporary buffer.
  2627.  
  2628.  
  2629.  
  2630.          WindowResizeHeight()
  2631.          --------------------
  2632.  
  2633.          This function changes the inside (text portion) height of
  2634.          the window.  Here is a prototype:
  2635.  
  2636.          int WindowResizeHeight(WPOINTER w, int newheight, int anchor)
  2637.  
  2638.          The newheight argument is the new height of the window.  If
  2639.          the height will exceed the bounds of the screen, the window
  2640.          is given its maximum height.  The anchor argument determines
  2641.          which side to "hold down" while the window is being resized.
  2642.          If the anchor is ANCHORTOP, the top line of the window is
  2643.          held in its current position and the window is resized
  2644.          accordingly.  If anchor is ANCHORBOTTOM, the bottom of the
  2645.  
  2646.  
  2647.          Page 30          The C Window Library               Page 30
  2648.  
  2649.          window is held and the window is resized accordingly.
  2650.  
  2651.          If there is text in the window, the text will be truncated
  2652.          if the window is made shorter (unless the window is a
  2653.          viewport to a virtual window.  Virtual windows are discussed
  2654.          in the VIRTUAL WINDOWS section).
  2655.  
  2656.          Example:
  2657.  
  2658.          #include "window.h"
  2659.  
  2660.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2661.  
  2662.          WPOINTER w;
  2663.  
  2664.          main()
  2665.          {
  2666.            WindowInitializeSystem();
  2667.            WindowSaveInitial(0);
  2668.            w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2669.            WindowOpen(w);
  2670.            WindowDisplay(w,1,NOEFFECT);
  2671.            GET_KEY();
  2672.            WindowResizeHeight(w,15,ANCHORTOP); /* height now is 15 */
  2673.            GET_KEY();
  2674.            WindowResizeHeight(w,5,ANCHORBOTTOM);/* height is now 5 */
  2675.          }
  2676.  
  2677.  
  2678.          If there were no errors, NO_ERROR is returned.
  2679.  
  2680.          If there is an error, WindowResizeHeight() returns one of
  2681.          the following values:
  2682.  
  2683.             BAD_WINDOW if the WPOINTER w does not exist.
  2684.  
  2685.             NO_HEAP_MEM if there was not enough memory to allocate
  2686.             for the resized window.
  2687.  
  2688.  
  2689.  
  2690.          WindowResizeWidth()
  2691.          -------------------
  2692.  
  2693.          This function changes the inside (text portion) width of the
  2694.          window.  Here is a prototype:
  2695.  
  2696.          int WindowResizeWidth(WPOINTER w, int newwidth, int anchor)
  2697.  
  2698.          The newwidth argument is the new width of the window.  If
  2699.          the width will exceed the bounds of the screen, the window
  2700.          is given its maximum width.  The anchor argument determines
  2701.          which side to "hold down" while the window is being resized.
  2702.          If the anchor is ANCHORLEFT, the left side of the window is
  2703.          held in its current position and the window is resized
  2704.  
  2705.  
  2706.  
  2707.          Page 31          The C Window Library               Page 31
  2708.  
  2709.          accordingly.  If anchor is ANCHORRIGHT, the right side of
  2710.          the window is held and the window is resized accordingly.
  2711.  
  2712.          If there is text in the window, the text will be truncated
  2713.          if the window is made shorter (unless the window is a
  2714.          viewport to a virtual window.  Virtual windows are discussed
  2715.          in the VIRTUAL WINDOWS section).
  2716.  
  2717.  
  2718.          main()
  2719.          {
  2720.            WindowInitializeSystem();
  2721.            WindowSaveInitial(0);
  2722.            w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2723.            WindowOpen(w);
  2724.            WindowDisplay(w,1,NOEFFECT);
  2725.            GET_KEY();
  2726.            WindowResizeWidth(w,15,ANCHORLEFT);/* width is now 15 */
  2727.            GET_KEY();
  2728.            WindowResizeWidth(w,5,ANCHORRIGHT);/* width is now 5 */
  2729.          }
  2730.  
  2731.  
  2732.          If there were no errors, NO_ERROR is returned.
  2733.  
  2734.          If there is an error, WindowResizeWidth() returns one of the
  2735.          following:
  2736.  
  2737.             BAD_WINDOW if the WPOINTER w does not exist.
  2738.  
  2739.             NO_HEAP_MEM if there was not enough memory to allocate
  2740.             for the resized window.
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.          Page 32          The C Window Library               Page 32
  2768.  
  2769.                        WRITING TEXT TO WINDOWS
  2770.                        -----------------------
  2771.  
  2772.          There are various functions that will write text to a window.
  2773.          These functions are divided into two groups:  Functions that
  2774.          specify a null terminated string, and functions that require
  2775.          the length of the string of characters to write to be an
  2776.          explicit argument.
  2777.  
  2778.  
  2779.          Null Terminated Write Functions
  2780.          -------------------------------
  2781.  
  2782.          WindowWriteString()
  2783.          -------------------
  2784.  
  2785.          The WindowWriteString() function writes a null terminated
  2786.          string of characters to a window at a specified row and
  2787.          column of the window.  If the string is too long to fit in
  2788.          the boundaries of the window, the string is clipped
  2789.          (truncated) to fit in the boundaries of the window.
  2790.  
  2791.          Here is the prototype:
  2792.  
  2793.          int WindowWriteString(WPOINTER w, char *string, int row,
  2794.                                int col)
  2795.  
  2796.          The first argument is the window to write the string to.  The
  2797.          second argument is the null terminated string to write.  The
  2798.          third and fourth arguments are the row and column of the
  2799.          window to place the string.  The video attribute used when
  2800.          writing the string is the video attribute of the inside of
  2801.          the window.
  2802.  
  2803.  
  2804.          Example:
  2805.  
  2806.  
  2807.          #include "window.h"
  2808.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2809.  
  2810.          WPOINTER w;
  2811.          int i;
  2812.  
  2813.          main()
  2814.          {
  2815.            WindowInitializeSystem();
  2816.            WindowSaveInitial(0);
  2817.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2818.            WindowOpen(w);
  2819.            WindowDisplay(w,1,NOEFFECT);
  2820.            GET_KEY();
  2821.            for (i=1;i<=10;i++)
  2822.              WindowWriteString(w,"Hello World",i,1);
  2823.          }
  2824.  
  2825.  
  2826.  
  2827.          Page 33          The C Window Library               Page 33
  2828.  
  2829.          The above example writes the string "Hello World" to each
  2830.          line of the window w.
  2831.  
  2832.          If there is no error WindowWriteString() returns NO_ERROR.
  2833.          If there is an error WindowWriteString() returns the
  2834.          following:
  2835.  
  2836.          BAD_WINDOW if the WPOINTER w does not exist.
  2837.  
  2838.          WINDOW_BOUND if the row or column specified are out of bounds
  2839.          of the window.
  2840.  
  2841.          WINDOW_NOT_OPEN if the window was not open for writing (did
  2842.          not use WindowOpen() on the window)
  2843.  
  2844.  
  2845.  
  2846.          WindowWriteStringAttr()
  2847.          -----------------------
  2848.  
  2849.          The WindowWriteStringAttr() function works the same as the
  2850.          WindowWriteString() function except that an extra argument
  2851.          determines the color used to write the string.  Here is the
  2852.          prototype:
  2853.  
  2854.          int WindowWriteStringAttr(WPOINTER w, char *string, int row,
  2855.                                    int col, int attr)
  2856.  
  2857.          The first argument is the window to write the string to.  The
  2858.          second argument is the null terminated string to write.  The
  2859.          third and fourth arguments are the row and column of the
  2860.          window to place the string. The last argument is the video
  2861.          attribute to use.
  2862.  
  2863.  
  2864.          Example:
  2865.  
  2866.  
  2867.          #include "window.h"
  2868.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2869.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2870.  
  2871.          WPOINTER w;
  2872.          int i;
  2873.  
  2874.          main()
  2875.          {
  2876.            WindowInitializeSystem();
  2877.            WindowSaveInitial(0);
  2878.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2879.            WindowOpen(w);
  2880.            WindowDisplay(w,1,NOEFFECT);
  2881.            GET_KEY();
  2882.            for (i=1;i<=10;i++)
  2883.              WindowWriteStringAttr(w,"Hello World",i,1,REVERSE);
  2884.          }
  2885.  
  2886.  
  2887.          Page 34          The C Window Library               Page 34
  2888.  
  2889.          The above example writes the string "Hello World" to each
  2890.          line of the window w using the video attribute defined by the
  2891.          constant REVERSE.
  2892.  
  2893.          The return values to WindowWriteStringAttr() are the same as
  2894.          WindowWriteString().
  2895.  
  2896.  
  2897.  
  2898.          WindowWriteCenterString()
  2899.          -------------------------
  2900.  
  2901.          The WindowWriteCenterString() function centers a null
  2902.          terminated string in a window.  Here is a prototype:
  2903.  
  2904.          int WindowWriteCenterString(WPOINTER w, char *string,
  2905.                                      int row)
  2906.  
  2907.          The first argument is the window.  The second argument is the
  2908.          string to write.  The third argument is the row that the
  2909.          string will be centered.
  2910.  
  2911.          The attribute used to write the string is the attribute of
  2912.          the inside of the window.
  2913.  
  2914.          Example:
  2915.  
  2916.          #include "window.h"
  2917.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2918.  
  2919.          WPOINTER w;
  2920.          int i;
  2921.  
  2922.          main()
  2923.          {
  2924.            WindowInitializeSystem();
  2925.            WindowSaveInitial(0);
  2926.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2927.            WindowOpen(w);
  2928.            WindowDisplay(w,1,NOEFFECT);
  2929.            GET_KEY();
  2930.            for (i=1;i<=10;i++)
  2931.              WindowWriteCenterString(w,"Hello World",i);
  2932.          }
  2933.  
  2934.  
  2935.          The above example writes and centers the string "Hello World"
  2936.          to each line of the window w.
  2937.  
  2938.          The return values for WindowWriteCenterString() are the same
  2939.          as WindowWriteString().
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.          Page 35          The C Window Library               Page 35
  2948.  
  2949.          WindowWriteCenterStringAttr()
  2950.          -----------------------------
  2951.  
  2952.          The WindowWriteCenterStringAttr() function works the same as
  2953.          the WindowWriteCenterString() function except that an extra
  2954.          argument determines the color used to write the string.  Here
  2955.          is the prototype:
  2956.  
  2957.          int WindowWriteCenterStringAttr(WPOINTER w, char *string,
  2958.                                          int row, int attr)
  2959.  
  2960.          The first argument is the window.  The second argument is the
  2961.          string to write.  The third argument is the row that the
  2962.          string will be centered.  The last argument is the video
  2963.          attribute to use to write the string.
  2964.  
  2965.          Example:
  2966.  
  2967.          #include "window.h"
  2968.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2969.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2970.  
  2971.          WPOINTER w;
  2972.          int i;
  2973.  
  2974.          main()
  2975.          {
  2976.            WindowInitializeSystem();
  2977.            WindowSaveInitial(0);
  2978.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2979.            WindowOpen(w);
  2980.            WindowDisplay(w,1,NOEFFECT);
  2981.            GET_KEY();
  2982.            for (i=1;i<=10;i++)
  2983.              WindowWriteCenterStringAttr(w,"Hello World",i,REVERSE);
  2984.          }
  2985.  
  2986.  
  2987.          The above example writes and centers the string "Hello World"
  2988.          to each line of the window w using REVERSE as the video
  2989.          attribute.
  2990.  
  2991.          The return values for WindowWriteCenterStringAttr() are the
  2992.          same as WindowWriteString().
  2993.  
  2994.  
  2995.  
  2996.          WindowWriteStringCC()
  2997.          ---------------------
  2998.  
  2999.          Centers and writes a string around a column of the window
  3000.          (the CC stands for Centered Column).  If the string is longer
  3001.          than the width of the window, the string is placed on column
  3002.          1 of the window and is clipped at the right edge of the
  3003.          window.  Here is the prototype:
  3004.  
  3005.  
  3006.  
  3007.          Page 36          The C Window Library               Page 36
  3008.  
  3009.          The attribute used to write the string is the attribute of
  3010.          the inside of the window.
  3011.  
  3012.          int WindowWriteStringCC(WPOINTER w, char *string, int row)
  3013.  
  3014.          The first argument is the window.  The second argument is the
  3015.          string. The third argument is the row to write the string,
  3016.          and the last argument is the column to center the string on.
  3017.  
  3018.  
  3019.          Example:
  3020.  
  3021.  
  3022.          #include "window.h"
  3023.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3024.  
  3025.          WPOINTER w;
  3026.  
  3027.          main()
  3028.          {
  3029.            WindowInitializeSystem();
  3030.            WindowSaveInitial(0);
  3031.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3032.            WindowOpen(w);
  3033.            WindowDisplay(w,1,NOEFFECT);
  3034.            GET_KEY();
  3035.            WindowWriteStringCC(w,"This",1,10);
  3036.            WindowWriteStringCC(w,"is",2,10);
  3037.            WindowWriteStringCC(w,"centered",3,10);
  3038.            WindowWriteStringCC(w,"around",4,10);
  3039.            WindowWriteStringCC(w,"column",5,10);
  3040.            WindowWriteStringCC(w,"10",6,10);
  3041.          }
  3042.  
  3043.          The example above writes the text centered around column 10
  3044.          of the window w.
  3045.  
  3046.          The return values for WindowWriteStringCC() are the same as
  3047.          WindowWriteString().
  3048.  
  3049.  
  3050.  
  3051.  
  3052.          WindowWriteStringCCAttr()
  3053.          -------------------------
  3054.  
  3055.          The WindowWriteStringCCAttr() function works the same as the
  3056.          WindowWriteStringCC() function except that an extra argument
  3057.          determines the color used to write the string.  Here is the
  3058.          prototype:
  3059.  
  3060.          int WindowWriteStringCCAttr(WPOINTER w, char *string,
  3061.                                      int row, int col, int attr)
  3062.  
  3063.          The first argument is the window.  The second argument is the
  3064.  
  3065.  
  3066.  
  3067.          Page 37          The C Window Library               Page 37
  3068.  
  3069.          string to write.  The third argument is the row that the
  3070.          string will be centered.  The column argument is the column
  3071.          to center the string on. The last argument is the video
  3072.          attribute to use to write the string.
  3073.  
  3074.          Example:
  3075.  
  3076.  
  3077.          #include "window.h"
  3078.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3079.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3080.  
  3081.          WPOINTER w;
  3082.  
  3083.          main()
  3084.          {
  3085.            WindowInitializeSystem();
  3086.            WindowSaveInitial(0);
  3087.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3088.            WindowOpen(w);
  3089.            WindowDisplay(w,1,NOEFFECT);
  3090.            GET_KEY();
  3091.            WindowWriteStringCCAttr(w,"This",1,10,REVERSE);
  3092.            WindowWriteStringCCAttr(w,"is",2,10,REVERSE);
  3093.            WindowWriteStringCCAttr(w,"centered",3,10,REVERSE);
  3094.            WindowWriteStringCCAttr(w,"around",4,10,REVERSE);
  3095.            WindowWriteStringCCAttr(w,"column",5,10,REVERSE);
  3096.            WindowWriteStringCCAttr(w,"10",6,10,REVERSE);
  3097.          }
  3098.  
  3099.  
  3100.          The example above writes the text centered around column 10
  3101.          of the window w using the video attribute REVERSE.
  3102.  
  3103.          The return values for WindowWriteStringCCAttr() are the same
  3104.          as WindowWriteString().
  3105.  
  3106.  
  3107.  
  3108.          WindowWriteStringRJ()
  3109.          ---------------------
  3110.  
  3111.          The WindowWriteStringRJ() function writes a right justified
  3112.          string.  Here is the prototype:
  3113.  
  3114.          int WindowWriteStringRJ(WPOINTER w, char *string, int row,
  3115.                                  int col)
  3116.  
  3117.          The first argument is the window.  The second argument is the
  3118.          string. The third argument is the row to write the string,
  3119.          and the last argument is the column to place the right edge
  3120.          of the string.
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.          Page 38          The C Window Library               Page 38
  3128.  
  3129.          Example:
  3130.  
  3131.          #include "window.h"
  3132.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3133.  
  3134.          WPOINTER w;
  3135.  
  3136.          main()
  3137.          {
  3138.            WindowInitializeSystem();
  3139.            WindowSaveInitial(0);
  3140.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3141.            WindowOpen(w);
  3142.            WindowDisplay(w,1,NOEFFECT);
  3143.            GET_KEY();
  3144.            WindowWriteStringRJ(w,"This",1,10);
  3145.            WindowWriteStringRJ(w,"is",2,10);
  3146.            WindowWriteStringRJ(w,"right",3,10);
  3147.            WindowWriteStringRJ(w,"justified",4,10);
  3148.            WindowWriteStringRJ(w,"on ",5,10);
  3149.            WindowWriteStringRJ(w,"column",6,10);
  3150.            WindowWriteStringRJ(w,"10",7,10);
  3151.          }
  3152.  
  3153.          The example above writes the text right justified on column
  3154.          10 of the window w.
  3155.  
  3156.          The attribute used to write the string is the attribute of
  3157.          the inside of the window.
  3158.  
  3159.          The return values for WindowWriteStringRJ() are the same as
  3160.          WindowWriteString().
  3161.  
  3162.  
  3163.  
  3164.          WindowWriteStringRJAttr()
  3165.          -------------------------
  3166.  
  3167.          The WindowWriteStringRJAttr() function works the same as the
  3168.          WindowWriteStringRJ() function except that an extra argument
  3169.          determines the color used to write the string.  Here is the
  3170.          prototype:
  3171.  
  3172.          int WindowWriteStringRJAttr(WPOINTER w, char *string,
  3173.                                      int row, int col, int attr)
  3174.  
  3175.          The first argument is the window.  The second argument is the
  3176.          string to write.  The third argument is the row to write the
  3177.          string.  The col is the column to right justify the string.
  3178.          The last argument is the video attribute to use to write the
  3179.          string.
  3180.  
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187.          Page 39          The C Window Library               Page 39
  3188.  
  3189.          Example:
  3190.  
  3191.          #include "window.h"
  3192.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3193.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3194.  
  3195.          WPOINTER w;
  3196.  
  3197.          main()
  3198.          {
  3199.            WindowInitializeSystem();
  3200.            WindowSaveInitial(0);
  3201.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3202.            WindowOpen(w);
  3203.            WindowDisplay(w,1,NOEFFECT);
  3204.            GET_KEY();
  3205.            WindowWriteStringRJAttr(w,"This",1,10,REVERSE);
  3206.            WindowWriteStringRJAttr(w,"is",2,10,REVERSE);
  3207.            WindowWriteStringRJAttr(w,"right",3,10,REVERSE);
  3208.            WindowWriteStringRJAttr(w,"justified",4,10,REVERSE);
  3209.            WindowWriteStringRJAttr(w,"on ",5,10,REVERSE);
  3210.            WindowWriteStringRJAttr(w,"column",6,10,REVERSE);
  3211.            WindowWriteStringRJAttr(w,"10",7,10,REVERSE);
  3212.          }
  3213.  
  3214.          The example above writes the text right justified at  column
  3215.          10 of the window w using the video attribute REVERSE.
  3216.  
  3217.          The return values for WindowWriteStringRJAttr() are the same
  3218.          as WindowWriteString().
  3219.  
  3220.  
  3221.  
  3222.  
  3223.          Length Controlled Write Functions
  3224.          ---------------------------------
  3225.  
  3226.          The upcoming functions must have the length explicitly stated
  3227.          as one of the arguments.  These functions do not stop writing
  3228.          characters if the null character in the string to write is
  3229.          reached.
  3230.  
  3231.  
  3232.  
  3233.  
  3234.          WindowWriteCharacters()
  3235.          -----------------------
  3236.  
  3237.          This function writes characters from a buffer to the window.
  3238.          Here is the prototype:
  3239.  
  3240.          int WindowWriteCharacters(WPOINTER w, char *buffer, int row,
  3241.                                    int col, int length)
  3242.  
  3243.          The first argument is the window.  The second argument is a
  3244.  
  3245.  
  3246.  
  3247.          Page 40          The C Window Library               Page 40
  3248.  
  3249.          pointer to the buffer where the characters are stored.  The
  3250.          third and fourth arguments are the (row,col) position in the
  3251.          window to write the string, and the last argument is the
  3252.          number of characters from buffer to write.  The attribute
  3253.          used is the attribute of the inside of the window.
  3254.  
  3255.  
  3256.          Example:
  3257.  
  3258.          #include "window.h"
  3259.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3260.  
  3261.          WPOINTER w;
  3262.          char buf[] = "Hello World!!";
  3263.  
  3264.          main()
  3265.          {
  3266.            WindowInitializeSystem();
  3267.            WindowSaveInitial(0);
  3268.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3269.            WindowOpen(w);
  3270.            WindowDisplay(w,1,NOEFFECT);
  3271.            GET_KEY();
  3272.            WindowWriteCharacters(w,buf,1,1,11);
  3273.            WindowWriteCharacters(w,buf,2,1,13);
  3274.          }
  3275.  
  3276.          The return values for WindowWriteCharacters() are the same as
  3277.          WindowWriteString().
  3278.  
  3279.  
  3280.  
  3281.  
  3282.          WindowWriteAttributes()
  3283.          -----------------------
  3284.  
  3285.          This function writes attributes from a buffer to the window.
  3286.          Here is the prototype:
  3287.  
  3288.          int WindowWriteAttributes(WPOINTER w, char *buffer, int row,
  3289.                                    int col, int length)
  3290.  
  3291.          The first argument is the window.  The second argument is a
  3292.          pointer to the buffer where the attributes are stored.  The
  3293.          third and fourth arguments are the (row,col) position in the
  3294.          window to write the string, and the last argument is the
  3295.          number of attributes from buffer to write.
  3296.  
  3297.  
  3298.          Example:
  3299.  
  3300.  
  3301.          #include "window.h"
  3302.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3303.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3304.  
  3305.  
  3306.  
  3307.          Page 41          The C Window Library               Page 41
  3308.  
  3309.          WPOINTER w;
  3310.          char buf[13];
  3311.  
  3312.          main()
  3313.          {
  3314.            int i;
  3315.            WindowInitializeSystem();
  3316.            WindowSaveInitial(0);
  3317.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3318.            WindowOpen(w);
  3319.            WindowDisplay(w,1,NOEFFECT);
  3320.  
  3321.            for (i=0;i<13;i++)
  3322.              if (i % 2)
  3323.                buf[i] = NORM;
  3324.              else
  3325.                buf[i] = REVERSE;
  3326.  
  3327.            WindowWriteString(w,"Hello World!!",1,1);
  3328.            GET_KEY();
  3329.            WindowWriteAttributes(w,buf,1,1,13);  /* Writes alternating
  3330.                                                     NORM and REVERSE
  3331.                                                     attributes */
  3332.          }
  3333.  
  3334.  
  3335.          The return values for WindowWriteAttributes() are the same as
  3336.          WindowWriteString().
  3337.  
  3338.  
  3339.  
  3340.  
  3341.          WindowWriteCharAndAttr()
  3342.          ------------------------
  3343.  
  3344.          The WindowWriteCharAndAttr() function writes a string of
  3345.          character/attribute pairs to a window.  Use this function if
  3346.          you have created a string of character/attribute pairs, and
  3347.          want to output them easily.  The string consists of character
  3348.          and attributes in the following manner:
  3349.  
  3350.                   char-attr-char-attr...
  3351.  
  3352.          Each character is followed by its corresponding video
  3353.          attribute.
  3354.  
  3355.  
  3356.          Here is the prototype:
  3357.  
  3358.          int WindowWriteCharAndAttr(WPOINTER w, char *buffer, int row,
  3359.                                     int col, int length)
  3360.  
  3361.  
  3362.          The first argument is the window. The second is the buffer
  3363.          where the character and attributes are stored.  The third and
  3364.  
  3365.  
  3366.  
  3367.          Page 42          The C Window Library               Page 42
  3368.  
  3369.          fourth is the (row,col) position in the window to write, and
  3370.          the length argument is the number of character/attribute
  3371.          pairs from the buffer to write.  Please note the difference
  3372.          in the meaning of the length argument in this function as
  3373.          opposed to its use in the preceding functions.
  3374.  
  3375.  
  3376.          Example:
  3377.  
  3378.  
  3379.          #include "window.h"
  3380.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3381.  
  3382.          WPOINTER w;
  3383.          char buf[26];
  3384.          char *str = "Hello World!!";
  3385.          main()
  3386.          {
  3387.            int i;
  3388.            WindowInitializeSystem();
  3389.            WindowSaveInitial(0);
  3390.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3391.            WindowOpen(w);
  3392.            WindowDisplay(w,1,NOEFFECT);
  3393.  
  3394.            for (i=0;i<26;i+=2,str++)
  3395.            {
  3396.              buf[i] = *str;
  3397.              buf[i+1] = NORM;
  3398.            }
  3399.  
  3400.            WindowWriteCharAndAttr(w,buf,1,1,13);
  3401.          }
  3402.  
  3403.  
  3404.          The return values for WindowWriteCharAndAttr() are the same as
  3405.          WindowWriteString().
  3406.  
  3407.  
  3408.  
  3409.          WindowWriteCharactersAttr()
  3410.          ---------------------------
  3411.  
  3412.          The WindowWriteCharactersAttr() function writes characters
  3413.          from a buffer to a window.  The difference between this
  3414.          function and WindowWriteCharacters() is that a video
  3415.          attribute is specified.  Here is the prototype:
  3416.  
  3417.          int WindowWriteCharactersAttr(WPOINTER w, char *buffer,
  3418.                                        int row, int col, int attr,
  3419.                                        int length)
  3420.  
  3421.          The attr argument is the video attribute to use when writing
  3422.          the characters.
  3423.  
  3424.  
  3425.  
  3426.  
  3427.          Page 43          The C Window Library               Page 43
  3428.  
  3429.          Example:
  3430.  
  3431.          #include "window.h"
  3432.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3433.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3434.  
  3435.  
  3436.          WPOINTER w;
  3437.          char buf[] = "Hello World!!";
  3438.  
  3439.          main()
  3440.          {
  3441.            WindowInitializeSystem();
  3442.            WindowSaveInitial(0);
  3443.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3444.            WindowOpen(w);
  3445.            WindowDisplay(w,1,NOEFFECT);
  3446.            GET_KEY();
  3447.            WindowWriteCharactersAttr(w,buf,2,1,REVERSE,13);
  3448.          }
  3449.  
  3450.  
  3451.          The return values for WindowWriteCharactersAttr() are the
  3452.          same as WindowWriteString().
  3453.  
  3454.  
  3455.  
  3456.          WindowWriteRepeatAttribute()
  3457.          ----------------------------
  3458.  
  3459.  
  3460.          The WindowWriteRepeatAttribute() function writes an attribute
  3461.          a specified number of times to a window.  Here is a
  3462.          prototype:
  3463.  
  3464.  
  3465.          int WindowWriteRepeatAttribute(WPOINTER w, int attr, int row,
  3466.                                         int col, int count)
  3467.  
  3468.  
  3469.          The attr argument is the attribute to use.  The count
  3470.          argument specifies the number of times to write the attribute
  3471.          attr to the window starting at (row,col).
  3472.  
  3473.          Example:
  3474.  
  3475.          #include "window.h"
  3476.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3477.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3478.  
  3479.          WPOINTER w;
  3480.  
  3481.          main()
  3482.          {
  3483.            WindowInitializeSystem();
  3484.  
  3485.  
  3486.  
  3487.          Page 44          The C Window Library               Page 44
  3488.  
  3489.            WindowSaveInitial(0);
  3490.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3491.            WindowOpen(w);
  3492.            WindowDisplay(w,1,NOEFFECT);
  3493.            WindowWriteString(w,"Hello World!!",1,1);
  3494.            GET_KEY();
  3495.            WindowWriteRepeatAttribute(w,REVERSE,1,1,13);
  3496.          }
  3497.  
  3498.          The example above illustrates that the
  3499.          WindowWriteRepeatAttribute() writes the REVERSE attribute 13
  3500.          times starting at row 1, column 1 of the window w.
  3501.  
  3502.          The return values for WindowWriteRepeatAttribute() are the
  3503.          same as WindowWriteString().
  3504.  
  3505.  
  3506.  
  3507.  
  3508.          WindowWriteRepeatCharacter()
  3509.          ----------------------------
  3510.  
  3511.          The WindowWriteRepeatCharacter() function writes a character
  3512.          a specified number of times to a window.  Here is a
  3513.          prototype:
  3514.  
  3515.  
  3516.          int WindowWriteRepeatCharacter(WPOINTER w, int ch, int row,
  3517.                                         int col, int count)
  3518.  
  3519.  
  3520.          The count argument is the character to use.  The count
  3521.          argument specifies the number of times to write the character
  3522.          ch to the window starting at (row,col).
  3523.  
  3524.          #include "window.h"
  3525.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3526.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3527.  
  3528.          WPOINTER w;
  3529.  
  3530.          main()
  3531.          {
  3532.            WindowInitializeSystem();
  3533.            WindowSaveInitial(0);
  3534.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3535.            WindowOpen(w);
  3536.            WindowDisplay(w,1,NOEFFECT);
  3537.            WindowWriteRepeatCharacter(w,'a',1,1,5);
  3538.            WindowWriteRepeatCharacter(w,'b',2,1,5);
  3539.            WindowWriteRepeatCharacter(w,'c',3,1,5);
  3540.          }
  3541.  
  3542.          The example above illustrates that the
  3543.          WindowWriteRepeatCharacter() writes the letter 'a', 'b', and
  3544.  
  3545.  
  3546.  
  3547.          Page 45          The C Window Library               Page 45
  3548.  
  3549.          'c' 5 times on rows 1, 2, and 3 respectively.
  3550.  
  3551.          The return values for WindowWriteRepeatCharacter() are the
  3552.          same as WindowWriteString().
  3553.  
  3554.  
  3555.  
  3556.          Formatted Write Functions
  3557.          -------------------------
  3558.  
  3559.          These functions write formatted output to windows just like
  3560.          the printf() function.  There are two functions that do this,
  3561.          namely WindowPrintf() and WindowPrintfAttr().  These
  3562.          functions use a format string that is similar to the format
  3563.          string found in printf().  For example, %d, %s, %lf, etc. and
  3564.          most of the escape sequences are supported.  The list of
  3565.          escape sequences supported are as follows:
  3566.  
  3567.                                \n - newline
  3568.                                \b - backspace
  3569.                                \t - tab
  3570.                                \a - bell
  3571.                                \r - carriage return
  3572.                                \x - hexadecimal
  3573.  
  3574.  
  3575.          Where output is placed in the window
  3576.          ------------------------------------
  3577.  
  3578.          The row and column of where the string will be written is
  3579.          determined by the window's logical cursor.  The logical
  3580.          cursor is advanced by both of these functions to one column
  3581.          position after the last character is printed.  If you want to
  3582.          start at a particular row and column of the window, you must
  3583.          move the cursor yourself by calling the WindowMoveCursor()
  3584.          function.  This function is explained later in the CURSOR
  3585.          POSITIONING IN WINDOWS section.  If the window is displayed,
  3586.          the logical cursor of the window is equivalent to the screen
  3587.          cursor.  If the output to the window will be obscured by
  3588.          other windows, the screen cursor will also be hidden.
  3589.  
  3590.          When the window is first opened using WindowOpen(), the
  3591.          logical cursor is automatically moved to (1,1) of the window.
  3592.  
  3593.  
  3594.          WindowSetWrap()
  3595.          ---------------
  3596.  
  3597.          With these functions, any text that will exceed the
  3598.          boundaries of the window will be wrapped to the next line.
  3599.          If the output will exceed the last row of the window, the
  3600.          window is automatically scrolled up by one line.  This is the
  3601.          default action that is taken when characters exceed the right
  3602.          edge of the window.  If you want the output clipped instead
  3603.          of wrapped, you must set the window's wrap flag using the
  3604.  
  3605.  
  3606.  
  3607.          Page 46          The C Window Library               Page 46
  3608.  
  3609.          WindowSetWrap() function.
  3610.  
  3611.          The WindowSetWrap() function sets the window's wrap flag to
  3612.          either on or off.  Here is the prototype:
  3613.  
  3614.                 int WindowSetWrap(WPOINTER w, int option)
  3615.  
  3616.          The second argument will be 0 if you want to turn the wrap
  3617.          flag off, or 1 if you want to turn it on.  If the wrap flag
  3618.          is off, the output generated by WindowPrintf() and
  3619.          WindowPrintfAttr() will be terminated when the right edge
  3620.          of the window is reached.  If the wrap flag is on, the output
  3621.          is wrapped to the next line when the right edge is reached,
  3622.          and the window will be scrolled up by one line if the output
  3623.          will exceed the last row.
  3624.  
  3625.          You can set the wrap flag to a window at any time.
  3626.  
  3627.  
  3628.  
  3629.          WindowPrintf()
  3630.          --------------
  3631.  
  3632.          The WindowPrintf() function writes formatted output to the
  3633.          window.  Here is the prototype:
  3634.  
  3635.             int WindowPrintf(WPOINTER w, char *format [,arg1,...])
  3636.  
  3637.          The first argument is the window.  The second argument is a
  3638.          format string.  The rest of the arguments are optional
  3639.          arguments that are written to the window.
  3640.  
  3641.          Example:
  3642.  
  3643.          #include "window.h"
  3644.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3645.          WPOINTER w;
  3646.          char *s1 = "This string will wrap around to the next line\n";
  3647.          char *s2 = "This escape code will ring the bell \a";
  3648.          int i = 3;
  3649.          double j = 5.6;
  3650.  
  3651.          main()
  3652.          {
  3653.            WindowInitializeSystem();
  3654.            WindowSaveInitial(0);
  3655.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  3656.            WindowOpen(w);
  3657.            WindowDisplay(w,1,NOEFFECT);
  3658.            WindowPrintf(w,"3+2 is equal to %d\n",3+2);
  3659.            GET_KEY();
  3660.            WindowPrintf(w,"i is equal to %d\nj is equal to %lf\n",i,j);
  3661.            GET_KEY();
  3662.            WindowPrintf(w,s1);
  3663.            GET_KEY();
  3664.  
  3665.  
  3666.  
  3667.          Page 47          The C Window Library               Page 47
  3668.  
  3669.            WindowPrintf(w,s2);
  3670.          }
  3671.  
  3672.          The above example illustrates how WindowPrintf() is used to
  3673.          print formatted strings.
  3674.  
  3675.          The return values for WindowPrintf() are the same as
  3676.          WindowWriteString().
  3677.  
  3678.  
  3679.  
  3680.          WindowPrintfAttr()
  3681.          ------------------
  3682.  
  3683.          The WindowPrintfAttr() function writes formatted output to
  3684.          the window.  The difference between WindowPrintf() and
  3685.          WindowPrintfAttr() is that WindowPrintfAttr() uses a video
  3686.          attribute specified as an argument.  Here is the prototype:
  3687.  
  3688.          int WindowPrintfAttr(WPOINTER w, int attr,
  3689.                               char *format [,arg1,...])
  3690.  
  3691.          The first argument is the window.  The second argument is the
  3692.          video attribute to use.  The third argument is the format
  3693.          string.  The rest of the arguments are optional arguments
  3694.          that are written to the window.
  3695.  
  3696.  
  3697.          Example:
  3698.  
  3699.          #include "window.h"
  3700.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3701.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3702.  
  3703.          WPOINTER w;
  3704.          char *s1 = "This string will wrap around to the next line\n";
  3705.          char *s2 = "This escape code will ring the bell \a";
  3706.          int i = 3;
  3707.          double j = 5.6;
  3708.  
  3709.          main()
  3710.          {
  3711.            WindowInitializeSystem();
  3712.            WindowSaveInitial(0);
  3713.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  3714.            WindowOpen(w);
  3715.            WindowDisplay(w,1,NOEFFECT);
  3716.            WindowPrintfAttr(w,REVERSE,"3+2 is equal to %d\n",3+2);
  3717.            GET_KEY();
  3718.            WindowPrintfAttr(w,REVERSE,
  3719.                      "i is equal to %d\nj is equal to %lf\n",i,j);
  3720.            GET_KEY();
  3721.            WindowPrintfAttr(w,REVERSE,s1);
  3722.            GET_KEY();
  3723.            WindowPrintfAttr(w,REVERSE,s2);
  3724.          }
  3725.  
  3726.  
  3727.          Page 48          The C Window Library               Page 48
  3728.  
  3729.          The above example illustrates how WindowPrintfAttr() is used
  3730.          to print formatted strings.
  3731.  
  3732.          The return values for WindowPrintfAttr() are the same as
  3733.          WindowWriteString().
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.  
  3771.  
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.          Page 49          The C Window Library               Page 49
  3788.  
  3789.                       WRITING TITLES TO WINDOWS
  3790.                       -------------------------
  3791.  
  3792.          This section only applies to bordered windows.  There are two
  3793.          methods of writing text to the top or bottom border of a
  3794.          window.  Each method has its advantages and disadvantages.
  3795.  
  3796.          The first method is to explicitly write to the border of the
  3797.          window.  Except for the WindowPrintf...() functions, if you
  3798.          specify the row number to be 0, the text is written on the
  3799.          upper border of the window. If the row number is equal to the
  3800.          window height + 1, the text is written on the lower border of
  3801.          the window.  To access the window's height use the macro
  3802.          WINDOW_HEIGHT() described later in the WINDOW MACROS section.
  3803.  
  3804.          If you want to write a formatted string on the border of the
  3805.          window, use the standard library function sprintf() to create
  3806.          a string of formatted output, and then write this string with
  3807.          one of the WindowWrite...() functions.
  3808.  
  3809.          Any text that is written on the borders of a window are not
  3810.          retained if the window is resized using one of the
  3811.          WindowResize...() functions, or if the border is changed
  3812.          using WindowDrawBorder().  Therefore it is a good idea to
  3813.          maintain what is on the borders of the window in your own
  3814.          string variables.
  3815.  
  3816.  
  3817.          Example:
  3818.  
  3819.  
  3820.          #include "window.h"
  3821.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3822.  
  3823.          WPOINTER w;
  3824.          int i;
  3825.  
  3826.          main()
  3827.          {
  3828.            WindowInitializeSystem();
  3829.            WindowSaveInitial(0);
  3830.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3831.            WindowOpen(w);
  3832.            WindowDisplay(w,1,NOEFFECT);
  3833.            GET_KEY();
  3834.  
  3835.            /* Specify row 0 to write on */
  3836.            WindowWriteCenterString(w,"This is a title",0);
  3837.  
  3838.            WindowWriteCenterString(w,"This is a title",
  3839.                                    WINDOW_HEIGHT(w) + 1);
  3840.          }
  3841.  
  3842.  
  3843.  
  3844.  
  3845.  
  3846.  
  3847.          Page 50          The C Window Library               Page 50
  3848.  
  3849.          The second method is writing a string of text to either the
  3850.          top or bottom border by using the WindowTitle...() functions.
  3851.          The advantage of using these functions is that the strings
  3852.          are retained automatically if the window is resized or the
  3853.          border type is changed.  Another advantage is that if the
  3854.          title does not fit in the boundaries of the window, the title
  3855.          is truncated, but the full title is retained in a buffer.  If
  3856.          the window is later resized so that the title can fit, the
  3857.          full title will appear on the border.
  3858.  
  3859.          The disadvantage is that only one string of text is allowed
  3860.          for the top and bottom borders, and there are only three
  3861.          positions on each border to place the title.
  3862.  
  3863.  
  3864.          WindowTitleTop()
  3865.          ----------------
  3866.  
  3867.          The WindowTitleTop() function writes a title to the top
  3868.          border of a window.  Here is the prototype:
  3869.  
  3870.          int WindowTitleTop(WPOINTER w, char *title, int pos)
  3871.  
  3872.          The first argument is the window to write the title.  The
  3873.          second argument is the title to write.  The third argument is
  3874.          the position to place the title.  Here is a list of valid
  3875.          constants to use for the position:
  3876.  
  3877.  
  3878.             TITLELEFT - Places the title starting at column 1 of the
  3879.                         window.
  3880.  
  3881.             TITLECENTER - Centers the title in the window.
  3882.  
  3883.             TITLERIGHT - Right justifies the title to the last column
  3884.                          of the window.
  3885.  
  3886.  
  3887.          Example:
  3888.  
  3889.          #include "window.h"
  3890.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3891.  
  3892.          WPOINTER w;
  3893.          int i;
  3894.          main()
  3895.          {
  3896.            WindowInitializeSystem();
  3897.            WindowSaveInitial(0);
  3898.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3899.            WindowOpen(w);
  3900.            WindowDisplay(w,1,NOEFFECT);
  3901.            GET_KEY();
  3902.  
  3903.            /* left justify title */
  3904.  
  3905.  
  3906.  
  3907.          Page 51          The C Window Library               Page 51
  3908.  
  3909.            WindowTitleTop(w,"This is a title",TITLELEFT);
  3910.            GET_KEY();
  3911.  
  3912.            /* center title */
  3913.            WindowTitleTop(w,"This is a title",TITLECENTER);
  3914.            GET_KEY();
  3915.            /* right justify title */
  3916.            WindowTitleTop(w,"This is a title",TITLERIGHT);
  3917.          }
  3918.  
  3919.  
  3920.          If there are no errors, WindowTitleTop() returns NO_ERROR.
  3921.          If there are errors, WindowTitleTop() returns one of the
  3922.          following:
  3923.  
  3924.          BAD_WINDOW if the window does not exist.
  3925.  
  3926.          WINDOW_NOT_OPEN if the window was not open for writing (use
  3927.          WindowOpen())
  3928.  
  3929.  
  3930.  
  3931.          WindowTitleBottom()
  3932.          -------------------
  3933.  
  3934.          The WindowTitleBottom() function writes a title to the bottom
  3935.          border of a window.  Here is the prototype:
  3936.  
  3937.          int WindowTitleBottom(WPOINTER w, char *title, int pos)
  3938.  
  3939.          The first argument is the window to write the title.  The
  3940.          second argument is the title to write.  The third argument is
  3941.          a constant that denotes the position to place the title.  A
  3942.          list of valid constants can be found in the description of
  3943.          WindowTitleBottom() described above.
  3944.  
  3945.  
  3946.          #include "window.h"
  3947.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3948.  
  3949.          WPOINTER w;
  3950.          int i;
  3951.          main()
  3952.          {
  3953.            WindowInitializeSystem();
  3954.            WindowSaveInitial(0);
  3955.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3956.            WindowOpen(w);
  3957.            WindowDisplay(w,1,NOEFFECT);
  3958.            GET_KEY();
  3959.  
  3960.            /* left justify title */
  3961.            WindowTitleBottom(w,"This is a title",TITLELEFT);
  3962.            GET_KEY();
  3963.  
  3964.  
  3965.  
  3966.  
  3967.          Page 52          The C Window Library               Page 52
  3968.  
  3969.            /* center title */
  3970.            WindowTitleBottom(w,"This is a title",TITLECENTER);
  3971.            GET_KEY();
  3972.  
  3973.            /* right justify title */
  3974.            WindowTitleBottom(w,"This is a title",TITLERIGHT);
  3975.          }
  3976.  
  3977.  
  3978.          If there are no errors, WindowTitleBottom() returns NO_ERROR.
  3979.          If there are errors, WindowTitleBottom() returns one of the
  3980.          following:
  3981.  
  3982.          BAD_WINDOW if the window does not exist.
  3983.  
  3984.          WINDOW_NOT_OPEN if the window was not open for writing (use
  3985.          WindowOpen())
  3986.  
  3987.  
  3988.  
  3989.  
  3990.  
  3991.          WindowTitleTopAttr()
  3992.          --------------------
  3993.  
  3994.          The WindowTitleTopAttr() function writes a title to the top
  3995.          border of a window with a specified color attribute.  Here is
  3996.          the prototype:
  3997.  
  3998.          int WindowTitleTopAttr(WPOINTER w, char *title, int pos,
  3999.                                 int attr)
  4000.  
  4001.          The first argument is the window to write the title.  The
  4002.          second argument is the title to write.  The third argument is
  4003.          a constant that denotes the position to place the title.  A
  4004.          list of valid constants can be found in the description of
  4005.          WindowTitleTopAttr() described above.  The fourth argument is
  4006.          the color attribute to use.
  4007.  
  4008.  
  4009.          #include "window.h"
  4010.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4011.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  4012.  
  4013.          WPOINTER w;
  4014.          int i;
  4015.          main()
  4016.          {
  4017.            WindowInitializeSystem();
  4018.            WindowSaveInitial(0);
  4019.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4020.            WindowOpen(w);
  4021.            WindowDisplay(w,1,NOEFFECT);
  4022.            GET_KEY();
  4023.  
  4024.  
  4025.  
  4026.  
  4027.          Page 53          The C Window Library               Page 53
  4028.  
  4029.            /* left justify title */
  4030.            WindowTitleTopAttr(w,"This is a title",TITLELEFT,REVERSE);
  4031.            GET_KEY();
  4032.  
  4033.            /* center title */
  4034.            WindowTitleTopAttr(w,"This is a title",TITLECENTER,REVERSE);
  4035.            GET_KEY();
  4036.  
  4037.            /* right justify title */
  4038.            WindowTitleTopAttr(w,"This is a title",TITLERIGHT,REVERSE);
  4039.          }
  4040.  
  4041.  
  4042.          If there are no errors, WindowTitleTopAttr() returns NO_ERROR.
  4043.          If there are errors, WindowTitleTopAttr() returns one of the
  4044.          following:
  4045.  
  4046.          BAD_WINDOW if the window does not exist.
  4047.  
  4048.          WINDOW_NOT_OPEN if the window was not open for writing (use
  4049.          WindowOpen())
  4050.  
  4051.  
  4052.  
  4053.  
  4054.          WindowTitleBottomAttr()
  4055.          -----------------------
  4056.  
  4057.          The WindowTitleBottomAttr() function writes a title to the
  4058.          bottom border of a window with a specified color attribute.
  4059.          Here is the prototype:
  4060.  
  4061.          int WindowTitleBottomAttr(WPOINTER w, char *title, int pos,
  4062.                                    int attr)
  4063.  
  4064.          The first argument is the window to write the title.  The
  4065.          second argument is the title to write.  The third argument is
  4066.          a constant that denotes the position to place the title.  A
  4067.          list of valid constants can be found in the description of
  4068.          WindowTitleBottomAttr() described above.  The fourth argument
  4069.          is the color attribute to use.
  4070.  
  4071.  
  4072.          #include "window.h"
  4073.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4074.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  4075.  
  4076.          WPOINTER w;
  4077.          int i;
  4078.          main()
  4079.          {
  4080.            WindowInitializeSystem();
  4081.            WindowSaveInitial(0);
  4082.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4083.            WindowOpen(w);
  4084.  
  4085.  
  4086.  
  4087.          Page 54          The C Window Library               Page 54
  4088.  
  4089.            WindowDisplay(w,1,NOEFFECT);
  4090.            GET_KEY();
  4091.  
  4092.            /* left justify title */
  4093.            WindowTitleBottomAttr(w,"This is a title",TITLELEFT,
  4094.                                  REVERSE);
  4095.            GET_KEY();
  4096.  
  4097.            /* center title */
  4098.            WindowTitleBottomAttr(w,"This is a title",TITLECENTER,
  4099.                                  REVERSE);
  4100.            GET_KEY();
  4101.  
  4102.            /* right justify title */
  4103.            WindowTitleBottomAttr(w,"This is a title",TITLERIGHT,
  4104.                                  REVERSE);
  4105.          }
  4106.  
  4107.  
  4108.          If there are no errors, WindowTitleBottomAttr() returns
  4109.          NO_ERROR.
  4110.  
  4111.          If there are errors, WindowTitleBottomAttr() returns one of
  4112.          the following:
  4113.  
  4114.          BAD_WINDOW if the window does not exist.
  4115.  
  4116.          WINDOW_NOT_OPEN if the window was not open for writing (use
  4117.          WindowOpen())
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.          Page 55          The C Window Library               Page 55
  4148.  
  4149.            READING CHARACTERS AND ATTRIBUTES FROM WINDOWS
  4150.            ----------------------------------------------
  4151.  
  4152.          With The C Window Library, you can read the contents of a
  4153.          window into a character buffer.  These functions provide the
  4154.          programmer with the contents of the window at any time.  The
  4155.          functions to perform this are WindowReadAttributes(),
  4156.          WindowReadCharacters(), and WindowReadCharAndAttr().
  4157.  
  4158.  
  4159.  
  4160.          WindowReadCharacters()
  4161.          ----------------------
  4162.  
  4163.          The WindowReadCharacters() function reads the characters from
  4164.          a window into a buffer.  Here is the prototype.
  4165.  
  4166.          int WindowReadCharacters(WPOINTER w, char *buffer, int row,
  4167.                                   int col, int length)
  4168.  
  4169.          The first argument is the window.  The second argument is the
  4170.          buffer to store the characters in.  The third and fourth
  4171.          arguments are the (row,col) position in the window to start
  4172.          reading from.  The last argument is the number of characters
  4173.          to read.
  4174.  
  4175.          You must make sure that buffer has enough room to hold all of
  4176.          the characters read in.
  4177.  
  4178.  
  4179.          Example:
  4180.  
  4181.          #include "window.h"
  4182.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4183.  
  4184.          WPOINTER w;
  4185.          char buf[14] = {0};      /* Null all elements of buf */
  4186.  
  4187.          main()
  4188.          {
  4189.            int i;
  4190.            WindowInitializeSystem();
  4191.            WindowSaveInitial(0);
  4192.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4193.            WindowOpen(w);
  4194.            WindowDisplay(w,1,NOEFFECT);
  4195.            WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  4196.            WindowReadCharacters(w,buf,1,1,13);  /* Read characters */
  4197.            GET_KEY();
  4198.            WindowWriteString(w,buf,2,1); /* Write what we have read */
  4199.          }
  4200.  
  4201.  
  4202.          The example above illustrates the use of
  4203.          WindowReadCharacters(), which reads the window's contents
  4204.  
  4205.  
  4206.  
  4207.          Page 56          The C Window Library               Page 56
  4208.  
  4209.          starting at (1,1) of the window.  This happens to be the
  4210.          string "Hello World!!".  After GET_KEY() is called, the
  4211.          results of the buffer are written on line 2 of the window.
  4212.  
  4213.          If the length exceeds the right edge of the window,
  4214.          WindowReadCharacters() will read up to the right edge of the
  4215.          window.
  4216.  
  4217.  
  4218.          If there are no errors, WindowReadCharacters() returns
  4219.          NO_ERROR.  If there are errors, WindowReadCharacters()
  4220.          returns one of the following:
  4221.  
  4222.          BAD_WINDOW if the window does not exist.
  4223.  
  4224.          WINDOW_NOT_OPEN if the window was not open for reading (use
  4225.          WindowOpen())
  4226.  
  4227.          WINDOW_BOUND if the row or column specified in the window is
  4228.          out of bounds.
  4229.  
  4230.  
  4231.  
  4232.  
  4233.          WindowReadAttributes()
  4234.          ----------------------
  4235.  
  4236.          The WindowReadAttributes() function reads the attributes from
  4237.          a window into a buffer.  Here is the prototype.
  4238.  
  4239.          int WindowReadAttributes(WPOINTER w, char *buffer, int row,
  4240.                                   int col, int length)
  4241.  
  4242.          The first argument is the window.  The second argument is the
  4243.          buffer to store the attributes in.  The third and fourth
  4244.          arguments are the (row,col) position in the window to start
  4245.          reading from.  The last argument is the number of attributes
  4246.          to read.
  4247.  
  4248.          You must make sure that buffer has enough room to hold all of
  4249.          the attributes read in.
  4250.  
  4251.  
  4252.          Example:
  4253.  
  4254.          #include "window.h"
  4255.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4256.  
  4257.          WPOINTER w;
  4258.          char buf[14] = {0};      /* Null all elements of buf */
  4259.  
  4260.          main()
  4261.          {
  4262.            int i;
  4263.            WindowInitializeSystem();
  4264.  
  4265.  
  4266.  
  4267.          Page 57          The C Window Library               Page 57
  4268.  
  4269.            WindowSaveInitial(0);
  4270.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4271.            WindowOpen(w);
  4272.            WindowDisplay(w,1,NOEFFECT);
  4273.            WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  4274.            WindowReadAttributes(w,buf,1,1,13);  /* Read attributes */
  4275.            GET_KEY();
  4276.            WindowWriteString(w,buf,2,1); /* Write what we have read */
  4277.          }
  4278.  
  4279.          The example above illustrates the use of
  4280.          WindowReadAttributes(), which reads the window's attribute
  4281.          contents starting at (1,1) of the window.  This happens to be
  4282.          the attributes of the string "Hello World!!", which is the
  4283.          NORM attribute.  After GET_KEY() is called, the results of
  4284.          the buffer are written on line 2 of the window.
  4285.  
  4286.          If the length exceeds the right edge of the window,
  4287.          WindowReadAttributes() will read up to the right edge of the
  4288.          window.
  4289.  
  4290.  
  4291.          If there are no errors, WindowReadAttributes() returns
  4292.          NO_ERROR.
  4293.  
  4294.          If there are errors, WindowReadAttributes() returns one of
  4295.          the following:
  4296.  
  4297.          BAD_WINDOW if the window does not exist.
  4298.  
  4299.          WINDOW_NOT_OPEN if the window was not open for reading (use
  4300.          WindowOpen())
  4301.  
  4302.          WINDOW_BOUND if the row or column specified in the window is
  4303.          out of bounds.
  4304.  
  4305.  
  4306.  
  4307.  
  4308.          WindowReadCharAndAttr()
  4309.          ----------------------
  4310.  
  4311.          The WindowReadCharAndAttr() function reads
  4312.          character/attribute pairs from a window into a buffer.  Here
  4313.          is the prototype.
  4314.  
  4315.          int WindowReadCharAndAttr(WPOINTER w, char *buffer, int row,
  4316.                                    int col, int length)
  4317.  
  4318.          The first argument is the window.  The second argument is the
  4319.          buffer to store the character/attribute pairs in.  The third
  4320.          and fourth arguments are the (row,col) position in the window
  4321.          to start reading from.  The last argument is the number of
  4322.          character/attribute pairs to read.
  4323.  
  4324.  
  4325.  
  4326.  
  4327.          Page 58          The C Window Library               Page 58
  4328.  
  4329.          You must make sure that buffer has enough room to hold all of
  4330.          the character/attribute pairs read in.
  4331.  
  4332.  
  4333.          Example:
  4334.  
  4335.          #include "window.h"
  4336.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4337.  
  4338.          WPOINTER w;
  4339.          char buf[27] = {0};      /* Null all elements of buf */
  4340.  
  4341.          main()
  4342.          {
  4343.            int i;
  4344.            WindowInitializeSystem();
  4345.            WindowSaveInitial(0);
  4346.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4347.            WindowOpen(w);
  4348.            WindowDisplay(w,1,NOEFFECT);
  4349.            WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  4350.            WindowReadCharAndAttr(w,buf,1,1,13);
  4351.            GET_KEY();
  4352.            WindowWriteCharAndAttr(w,buf,2,1,13); /* Write what we have
  4353.                                                     read */
  4354.          }
  4355.  
  4356.          The example above illustrates the use of
  4357.          WindowReadCharAndAttr(), which reads the window's
  4358.          character/attribute contents starting at (1,1) of the window.
  4359.          This happens to be the characters/attributes of the string
  4360.          "Hello World!!".  After GET_KEY() is called, the results of
  4361.          the buffer are written on line 2 of the window.
  4362.  
  4363.          If the length exceeds the right edge of the window,
  4364.          WindowReadCharAndAttr() will read up to the right edge of the
  4365.          window.
  4366.  
  4367.  
  4368.          If there are no errors, WindowReadCharAndAttr() returns
  4369.          NO_ERROR.
  4370.  
  4371.          If there are errors, WindowReadCharAndAttr() returns one of
  4372.          the following:
  4373.  
  4374.          BAD_WINDOW if the window does not exist.
  4375.  
  4376.          WINDOW_NOT_OPEN if the window was not open for reading (use
  4377.          WindowOpen())
  4378.  
  4379.          WINDOW_BOUND if the row or column specified in the window is
  4380.          out of bounds.
  4381.  
  4382.  
  4383.  
  4384.  
  4385.  
  4386.  
  4387.          Page 59          The C Window Library               Page 59
  4388.  
  4389.                            HIDING WINDOWS
  4390.                            --------------
  4391.  
  4392.          With The C Window Library, you can hide windows at any time
  4393.          without disturbing the contents of other windows.
  4394.  
  4395.  
  4396.  
  4397.          WindowHide()
  4398.          ------------
  4399.  
  4400.          The WindowHide() function hides a window on the screen from
  4401.          view.  The window retains all text and shadows that may be
  4402.          present.  Here is a prototype:
  4403.  
  4404.                    int WindowHide(WPOINTER w, int effect)
  4405.  
  4406.          The first argument is the window, and the last argument is
  4407.          the special effect to use when hiding the window.  For a list
  4408.          of special effects, refer to the DISPLAYING WINDOWS section.
  4409.  
  4410.          Example :
  4411.  
  4412.  
  4413.          #include "window.h"
  4414.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4415.          #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4416.          #define BLACKONWHITE  CREATE_VIDEO_ATTRIBUTE(white,black)
  4417.  
  4418.  
  4419.          WPOINTER w1,w2,w3;
  4420.  
  4421.          main()
  4422.          {
  4423.            WindowInitializeSystem();
  4424.            WindowSaveInitial(0);
  4425.  
  4426.            /* Initialize all windows */
  4427.            w1 = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4428.            w2 = WindowInitialize(BORDER,2,2,20,10,REDONWHITE,NORM,
  4429.                                  DOUBLEBOX);
  4430.            w3 = WindowInitialize(BORDER,3,3,20,10,BLACKONWHITE,NORM,
  4431.                                  SINGLEBOX);
  4432.  
  4433.            /* Open all windows */
  4434.            WindowOpen(w1);
  4435.            WindowOpen(w2);
  4436.            WindowOpen(w3);
  4437.  
  4438.            /* Display All windows */
  4439.            WindowDisplay(w1,1,NOEFFECT);
  4440.            WindowDisplay(w2,2,NOEFFECT);
  4441.            WindowDisplay(w3,3,NOEFFECT);
  4442.  
  4443.            WindowWriteString(w1,"This is window 1",1,1);
  4444.  
  4445.  
  4446.  
  4447.          Page 60          The C Window Library               Page 60
  4448.  
  4449.            WindowWriteString(w2,"This is window 2",2,1);
  4450.            WindowWriteString(w3,"This is window 3",3,1);
  4451.  
  4452.            GET_KEY();
  4453.            WindowHide(w3,NOEFFECT);
  4454.            GET_KEY();
  4455.            WindowHide(w2,BRICKS);
  4456.            GET_KEY();
  4457.            WindowHide(w1,CONTRACT);
  4458.          }
  4459.  
  4460.  
  4461.          The example initializes, opens, and displays three windows.
  4462.          Note that you can hide windows regardless of the order in
  4463.          which they were displayed.  This makes for very flexible
  4464.          window management.
  4465.  
  4466.          If there is no error, WindowHide() returns NO_ERROR.
  4467.  
  4468.          The only error that can occur is if the WPOINTER w does not
  4469.          exist.  WindowHide() returns BAD_WINDOW if this is the case.
  4470.  
  4471.  
  4472.  
  4473.  
  4474.  
  4475.  
  4476.  
  4477.  
  4478.  
  4479.  
  4480.  
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.  
  4494.  
  4495.  
  4496.  
  4497.  
  4498.  
  4499.  
  4500.  
  4501.  
  4502.  
  4503.  
  4504.  
  4505.  
  4506.  
  4507.          Page 61          The C Window Library               Page 61
  4508.  
  4509.                      CREATING COPIES OF A WINDOW
  4510.                      ---------------------------
  4511.  
  4512.          You can create copies of a window without going through the
  4513.          WindowInitialize(), WindowOpen(), etc. cycle.
  4514.  
  4515.  
  4516.          WindowCopy()
  4517.          ------------
  4518.  
  4519.          The WindowCopy() function makes a copy of a previous window.
  4520.          The copy will have the same colors, border type, shadow, and
  4521.          may have the same text as a previous window.  If the original
  4522.          window is a viewport on a virtual window (virtual windows are
  4523.          discussed later in the VIRTUAL WINDOWS section), the copy can
  4524.          also be made a viewport on the same virtual window.  The only
  4525.          thing that will not be copied is the (row,col) of the
  4526.          original window.  You supply the position of the new window.
  4527.          Here is the prototype:
  4528.  
  4529.          WPOINTER WindowCopy(WPOINTER w, int row, int col, int options)
  4530.  
  4531.          Please note that WindowCopy() returns a new WPOINTER.  You
  4532.          must assign the return value to a WPOINTER or you will not
  4533.          get easy access to the newly created window.
  4534.  
  4535.          The first argument is the original window to copy.  This
  4536.          window must already exist.  The second and third arguments
  4537.          are the coordinates of where to place the new window.  The
  4538.          last argument are additional options that control whether the
  4539.          window will contain the same text as the previous window, and
  4540.          if the new window will be made a viewport if the original
  4541.          window is a viewport.  The constants used for options is as
  4542.          follows:
  4543.  
  4544.          options             action
  4545.          -------             ------
  4546.  
  4547.          COPYTEXT            Makes a copy of the text area of the
  4548.                              original window.
  4549.  
  4550.          MAKEVIEWPORT        Turns the copy into a viewport if the
  4551.                              original is a viewport.
  4552.  
  4553.          NO_OPTIONS          No options desired.
  4554.  
  4555.  
  4556.          As was stated before, viewports are discussed in the VIRTUAL
  4557.          WINDOW section of the manual.  If options is NO_OPTIONS, the
  4558.          windows size, border type, shadow (if there is a shadow) and
  4559.          colors are copied.
  4560.  
  4561.  
  4562.  
  4563.  
  4564.  
  4565.  
  4566.  
  4567.          Page 62          The C Window Library               Page 62
  4568.  
  4569.          Example:
  4570.  
  4571.          #include "window.h"
  4572.  
  4573.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4574.  
  4575.          WPOINTER w,w2;
  4576.  
  4577.          main()
  4578.          {
  4579.            WindowInitializeSystem();
  4580.            WindowSaveInitial(0);
  4581.            w = WindowInitialize(BORDER,1,1,45,10,NORM,NORM,SINGLEBOX);
  4582.            WindowOpen(w);
  4583.            WindowDisplay(w,1,NOEFFECT);
  4584.            WindowWriteString(w,
  4585.                        "This will be copied to the new window",1,1);
  4586.            GET_KEY();
  4587.            w2 = WindowCopy(w,3,3,COPYTEXT);  /* Make a copy of w */
  4588.            WindowDisplay(w2,1,NOEFFECT);     /* Display this copy */
  4589.            GETKEY();
  4590.            WindowFreeAll(0,NOEFFECT);
  4591.          }
  4592.  
  4593.  
  4594.          If there is no error, WindowCopy() returns a valid WPOINTER.
  4595.  
  4596.          If there is an error, WindowCopy() returns a WIN_NULL_PTR (a
  4597.          null window pointer) and sets window_error_code to one of the
  4598.          following values:
  4599.  
  4600.           NO_HEAP_MEM if there is not enough memory to allocate for
  4601.           the window structure.
  4602.  
  4603.           BAD_WINDOW_SIZE if the dimensions for the window are too
  4604.           large for the physical screen.
  4605.  
  4606.           MAX_WINDOW if there are > 254 windows defined.
  4607.  
  4608.  
  4609.  
  4610.  
  4611.  
  4612.  
  4613.  
  4614.  
  4615.  
  4616.  
  4617.  
  4618.  
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.  
  4626.  
  4627.          Page 63          The C Window Library               Page 63
  4628.  
  4629.                       SCROLLING TEXT IN WINDOWS
  4630.                       -------------------------
  4631.  
  4632.          With The C Window Library, you can scroll text in a window
  4633.          up, or down, or scroll just particular regions of a window.
  4634.          The functions used to scroll windows are WindowScroll(),
  4635.          WindowScrollAttr(), WindowScrollRegion(), and
  4636.          WindowScrollRegionAttr().
  4637.  
  4638.          When specifying a direction, use the constant UP to scroll up
  4639.          or DOWN to scroll down.  These constants are defined in
  4640.          window.h.
  4641.  
  4642.  
  4643.  
  4644.          WindowScroll()
  4645.          --------------
  4646.  
  4647.          If you want to scroll the entire window either up or down,
  4648.          you can use the WindowScroll() function.  Here is a
  4649.          prototype:
  4650.  
  4651.            int WindowScroll(WPOINTER w, int numlines, int direction)
  4652.  
  4653.  
  4654.          The first argument is the window to scroll.   The second
  4655.          argument is the number of lines to scroll. The last argument
  4656.          is the direction to scroll the window (either UP or DOWN).
  4657.  
  4658.  
  4659.          Example:
  4660.  
  4661.          #include "window.h"
  4662.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4663.  
  4664.          WPOINTER w;
  4665.  
  4666.          main()
  4667.          {
  4668.            int i;
  4669.            WindowInitializeSystem();
  4670.            WindowSaveInitial(0);
  4671.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4672.            WindowOpen(w);
  4673.            WindowDisplay(w,1,NOEFFECT);
  4674.            for (i=0;i<10;i++)
  4675.              WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4676.            GET_KEY();
  4677.            WindowScroll(w,1,UP);
  4678.            GET_KEY();
  4679.            WindowScroll(w,3,DOWN);
  4680.          }
  4681.  
  4682.          The above example creates text using
  4683.          WindowWriteRepeatCharacter() function.  The WindowScroll()
  4684.  
  4685.  
  4686.  
  4687.          Page 64          The C Window Library               Page 64
  4688.  
  4689.          calls will scroll the window up by one line, and then scroll
  4690.          the window down by 3 lines.
  4691.  
  4692.          If there is no error, WindowScroll() returns NO_ERROR.
  4693.          If there is an error, WindowScroll() will return the
  4694.          following values:
  4695.  
  4696.          BAD_WINDOW if the WPOINTER w does not exist.
  4697.  
  4698.          WINDOW_NOT_OPEN if the window was not open for writing (use
  4699.          WindowOpen() to open the window for writing).
  4700.  
  4701.  
  4702.  
  4703.  
  4704.          WindowScrollRegion()
  4705.          --------------------
  4706.  
  4707.          The WindowScrollRegion() functions scrolls a specified region
  4708.          of a window.  To use the WindowScrollRegion() function, you
  4709.          must describe the rectangular region to scroll.  Here is the
  4710.          prototype:
  4711.  
  4712.          int WindowScrollRegion(WPOINTER w, int numlines, int urow,
  4713.                                 int ucol, int lrow,
  4714.                                 int lcol, int direction)
  4715.  
  4716.          Arguments 3 thru 6 describe the rectangular region.  They are
  4717.          in the order of upper left row, upper left column, lower
  4718.          right row, lower right column.  All of these coordinates are
  4719.          window relative.  The second argument is the number of lines
  4720.          to scroll.  The last argument is the direction.
  4721.  
  4722.  
  4723.          Example:
  4724.  
  4725.          #include "window.h"
  4726.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4727.  
  4728.          WPOINTER w;
  4729.  
  4730.          main()
  4731.          {
  4732.            int i;
  4733.            WindowInitializeSystem();
  4734.            WindowSaveInitial(0);
  4735.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4736.            WindowOpen(w);
  4737.            WindowDisplay(w,1,NOEFFECT);
  4738.            for (i=0;i<10;i++)
  4739.              WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4740.            GET_KEY();
  4741.            WindowScrollRegion(w,1,2,2,4,10,UP);
  4742.            GET_KEY();
  4743.            WindowScrollRegion(w,3,7,2,9,8,DOWN);
  4744.          }
  4745.  
  4746.  
  4747.          Page 65          The C Window Library               Page 65
  4748.  
  4749.          The above example creates text using
  4750.          WindowWriteRepeatCharacter() function.  The first
  4751.          WindowScrollRegion() call will scroll the region described by
  4752.          the rectangular coordinates (2,2) and (4,10).  This region is
  4753.          scrolled up one line.  The second call to
  4754.          WindowScrollRegion() scrolls the region defined by the
  4755.          rectangular region (7,2) and (9,8).  This region is scrolled
  4756.          down by three lines.
  4757.  
  4758.          If there is no error, WindowScrollRegion() returns NO_ERROR.
  4759.  
  4760.          If there is an error, the WindowScrollRegion() function will
  4761.          return of the following values:
  4762.  
  4763.          BAD_WINDOW if the WPOINTER w does not exist.
  4764.  
  4765.          WINDOW_BOUND if the rectangular region defined is out of
  4766.          bounds of the window.
  4767.  
  4768.          WINDOW_NOT_OPEN if the window was not open for writing (use
  4769.          WindowOpen() to open the window for writing).
  4770.  
  4771.  
  4772.  
  4773.  
  4774.          WindowScrollAttr()
  4775.          ------------------
  4776.  
  4777.          This function works the same way as the WindowScroll()
  4778.          function except that an attribute is defined for the blank
  4779.          lines that are created when the window is scrolled.  Here is
  4780.          a prototype:
  4781.  
  4782.          int WindowScrollAttr(WPOINTER w, int numlines, int direction,
  4783.                               int attr)
  4784.  
  4785.          The last argument is the attribute to use for the blank lines
  4786.          created.
  4787.  
  4788.          Example:
  4789.  
  4790.          #include "window.h"
  4791.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4792.          #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4793.  
  4794.          WPOINTER w;
  4795.  
  4796.          main()
  4797.          {
  4798.            int i;
  4799.            WindowInitializeSystem();
  4800.            WindowSaveInitial(0);
  4801.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4802.            WindowOpen(w);
  4803.            WindowDisplay(w,1,NOEFFECT);
  4804.  
  4805.  
  4806.  
  4807.          Page 66          The C Window Library               Page 66
  4808.  
  4809.            for (i=0;i<10;i++)
  4810.              WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4811.            GET_KEY();
  4812.            WindowScrollAttr(w,1,UP,REDONWHITE);
  4813.            GET_KEY();
  4814.            WindowScrollAttr(w,3,DOWN,REDONWHITE);
  4815.          }
  4816.  
  4817.          The above example creates text using
  4818.          WindowWriteRepeatCharacter() function.  The
  4819.          WindowScrollAttr() calls will scroll the window up by one
  4820.          line, and then scroll the window down by 3 lines with both
  4821.          scrolls using REDONWHITE as the video attribute.
  4822.  
  4823.          WindowScrollAttr() returns the same values as WindowScroll().
  4824.  
  4825.  
  4826.  
  4827.  
  4828.          WindowScrollRegionAttr()
  4829.          ------------------------
  4830.  
  4831.          This function works the same way as the WindowScrollRegion()
  4832.          function except that an attribute is defined for the blank
  4833.          lines that are created when the window is scrolled.  Here is
  4834.          a prototype:
  4835.  
  4836.          int WindowScrollRegionAttr(WPOINTER w, int numlines, int
  4837.                                    int urow, int ucol, int lrow,
  4838.                                    int lcol, int direction, int attr)
  4839.  
  4840.          The last argument is the attribute to use for the blank lines
  4841.          created.
  4842.  
  4843.  
  4844.          Example:
  4845.  
  4846.          #include "window.h"
  4847.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4848.          #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  4849.  
  4850.          WPOINTER w;
  4851.  
  4852.          main()
  4853.          {
  4854.            int i;
  4855.            WindowInitializeSystem();
  4856.            WindowSaveInitial(0);
  4857.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4858.            WindowOpen(w);
  4859.            WindowDisplay(w,1,NOEFFECT);
  4860.            for (i=0;i<10;i++)
  4861.              WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  4862.            GET_KEY();
  4863.            WindowScrollRegionAttr(w,1,3,5,6,15,UP,REDONWHITE);
  4864.  
  4865.  
  4866.  
  4867.          Page 67          The C Window Library               Page 67
  4868.  
  4869.            GET_KEY();
  4870.            WindowScrollRegionAttr(w,3,8,4,10,12,DOWN,REDONWHITE);
  4871.          }
  4872.  
  4873.  
  4874.          The above example creates text using
  4875.          WindowWriteRepeatCharacter() function.  The first
  4876.          WindowScrollRegionAttr() call will scroll the region
  4877.          described by the rectangular coordinates (2,2) and (4,10).
  4878.          This region is scrolled one line.  The second call to
  4879.          WindowScrollRegionAttr() scrolls the region defined by the
  4880.          rectangular region (7,2) and (9,8).  This region is scrolled
  4881.          down by three lines.  All blank lines use the video attribute
  4882.          REDONWHITE.
  4883.  
  4884.          WindowScrollRegionAttr() returns the same values as
  4885.          WindowScrollRegion().
  4886.  
  4887.  
  4888.  
  4889.  
  4890.  
  4891.  
  4892.  
  4893.  
  4894.  
  4895.  
  4896.  
  4897.  
  4898.  
  4899.  
  4900.  
  4901.  
  4902.  
  4903.  
  4904.  
  4905.  
  4906.  
  4907.  
  4908.  
  4909.  
  4910.  
  4911.  
  4912.  
  4913.  
  4914.  
  4915.  
  4916.  
  4917.  
  4918.  
  4919.  
  4920.  
  4921.  
  4922.  
  4923.  
  4924.  
  4925.  
  4926.  
  4927.          Page 68          The C Window Library               Page 68
  4928.  
  4929.                           CLEARING WINDOWS
  4930.                           ----------------
  4931.  
  4932.          The C Window Library contains functions that clears the
  4933.          entire window, or clears defined rectangular regions of the
  4934.          window.
  4935.  
  4936.  
  4937.          WindowClear()
  4938.          -------------
  4939.  
  4940.          The WindowClear() function clears an entire window to spaces.
  4941.          The attribute used is the current attribute of the text area
  4942.          of the window.  Here is the prototype:
  4943.  
  4944.                        int WindowClear(WPOINTER w)
  4945.  
  4946.          The only argument is the window to clear.
  4947.  
  4948.          Example:
  4949.  
  4950.          #include "window.h"
  4951.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4952.  
  4953.          WPOINTER w;
  4954.  
  4955.          main()
  4956.          {
  4957.            int i;
  4958.            WindowInitializeSystem();
  4959.            WindowSaveInitial(0);
  4960.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4961.            WindowOpen(w);
  4962.            WindowDisplay(w,1,NOEFFECT);
  4963.            for (i=1;i<=10;i++)
  4964.              WindowWriteString(w,"Hello World!!",i,1);
  4965.            GET_KEY();
  4966.            WindowClear(w);
  4967.          }
  4968.  
  4969.          If there is no error, WindowClear() returns NO_ERROR.
  4970.  
  4971.          If there is an error, WindowClear() returns the following
  4972.          values:
  4973.  
  4974.          BAD_WINDOW if the WPOINTER w does not exist.
  4975.  
  4976.          WINDOW_NOT_OPEN if the window is not open for writing (use
  4977.          WindowOpen() to open the window for writing).
  4978.  
  4979.  
  4980.  
  4981.  
  4982.  
  4983.  
  4984.  
  4985.  
  4986.  
  4987.          Page 69          The C Window Library               Page 69
  4988.  
  4989.          WindowClearAttr()
  4990.          -----------------
  4991.  
  4992.          The WindowClearAttr() function works the same way as the
  4993.          WindowClear() function except that an attribute is specified.
  4994.          Here is the prototype:
  4995.  
  4996.             int WindowClearAttr(WPOINTER w, int attr)
  4997.  
  4998.          The second argument is the video attribute to use.
  4999.  
  5000.  
  5001.          Example:
  5002.  
  5003.          #include "window.h"
  5004.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5005.          #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  5006.  
  5007.          WPOINTER w;
  5008.  
  5009.          main()
  5010.          {
  5011.            int i;
  5012.            WindowInitializeSystem();
  5013.            WindowSaveInitial(0);
  5014.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  5015.            WindowOpen(w);
  5016.            WindowDisplay(w,1,NOEFFECT);
  5017.            for (i=1;i<=10;i++)
  5018.              WindowWriteString(w,"Hello World!!",i,1);
  5019.            GET_KEY();
  5020.            WindowClearAttr(w,REDONWHITE);
  5021.          }
  5022.  
  5023.          The return values for WindowClearAttr() are the same as
  5024.          WindowClear().
  5025.  
  5026.  
  5027.  
  5028.          WindowClearRegion()
  5029.          -------------------
  5030.  
  5031.          The WindowClearRegion() function clears a region of a window.
  5032.          To use the WindowClearRegion() function, you must describe
  5033.          the rectangular region to clear.  Here is the prototype:
  5034.  
  5035.          int WindowClearRegion(WPOINTER w, int urow, int ucol,
  5036.                                int lrow, int lcol)
  5037.  
  5038.          where (urow,ucol) describes the upper left of the rectangle
  5039.          and (lrow,lcol) is the lower right of the window.  These
  5040.          coordinates are window relative.
  5041.  
  5042.  
  5043.  
  5044.  
  5045.  
  5046.  
  5047.          Page 70          The C Window Library               Page 70
  5048.  
  5049.          Example:
  5050.  
  5051.          #include "window.h"
  5052.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5053.  
  5054.          WPOINTER w;
  5055.  
  5056.          main()
  5057.          {
  5058.            int i;
  5059.            WindowInitializeSystem();
  5060.            WindowSaveInitial(0);
  5061.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  5062.            WindowOpen(w);
  5063.            WindowDisplay(w,1,NOEFFECT);
  5064.            for (i=1;i<=10;i++)
  5065.              WindowWriteString(w,"Hello World!!",i,1);
  5066.            GET_KEY();
  5067.            WindowClearRegion(w,4,4,8,15);
  5068.          }
  5069.  
  5070.  
  5071.          The WindowClearRegion() call will clear the region described
  5072.          by the rectangular coordinates (4,4) and (8,15).
  5073.  
  5074.          If there is no error, WindowClearRegion() returns NO_ERROR.
  5075.  
  5076.          If there is an error, the WindowClearRegion() function will
  5077.          return the following values:
  5078.  
  5079.          BAD_WINDOW if the WPOINTER w does not exist.
  5080.  
  5081.          WINDOW_BOUND if the rectangular region defined is out of
  5082.          bounds of the window.
  5083.  
  5084.          WINDOW_NOT_OPEN if the window is not open for writing (use
  5085.          WindowOpen() to open the window for writing).
  5086.  
  5087.  
  5088.  
  5089.  
  5090.  
  5091.          WindowClearRegionAttr()
  5092.          -----------------------
  5093.  
  5094.          The WindowClearRegionAttr() function works the same as the
  5095.          WindowClearRegion() function, except that a video attribute
  5096.          is specified.  Here is the prototype:
  5097.  
  5098.          int WindowClearRegionAttr(WPOINTER w, int urow, int ucol,
  5099.                                    int lrow, int lcol, int attr)
  5100.  
  5101.          The attr argument is a video attribute to use to clear the
  5102.          region.
  5103.  
  5104.  
  5105.  
  5106.  
  5107.          Page 71          The C Window Library               Page 71
  5108.  
  5109.          Example:
  5110.  
  5111.          #include "window.h"
  5112.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5113.          #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  5114.  
  5115.          WPOINTER w;
  5116.  
  5117.          main()
  5118.          {
  5119.            int i;
  5120.            WindowInitializeSystem();
  5121.            WindowSaveInitial(0);
  5122.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  5123.            WindowOpen(w);
  5124.            WindowDisplay(w,1,NOEFFECT);
  5125.            for (i=1;i<=10;i++)
  5126.              WindowWriteString(w,"Hello World!!",i,1);
  5127.            GET_KEY();
  5128.            WindowClearRegionAttr(w,4,4,8,15,REDONWHITE);
  5129.          }
  5130.  
  5131.  
  5132.          The WindowClearRegionAttr() call will clear the region
  5133.          described by the rectangular coordinates (4,4) and (8,15)
  5134.          using the video attribute defined by the constant REDONWHITE.
  5135.  
  5136.          The WindowClearRegionAttr() returns the same values as
  5137.          WindowClearRegion().
  5138.  
  5139.  
  5140.  
  5141.  
  5142.  
  5143.  
  5144.  
  5145.  
  5146.  
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.  
  5153.  
  5154.  
  5155.  
  5156.  
  5157.  
  5158.  
  5159.  
  5160.  
  5161.  
  5162.  
  5163.  
  5164.  
  5165.  
  5166.  
  5167.          Page 72          The C Window Library               Page 72
  5168.  
  5169.                   WRITING WINDOW CONTENTS TO A FILE
  5170.                   ---------------------------------
  5171.  
  5172.          The C Window Library allows you to print the contents of a
  5173.          window using the WindowWriteTextToFile() function.
  5174.  
  5175.  
  5176.          WindowWriteTextToFile()
  5177.          -----------------------
  5178.  
  5179.          The WindowWriteTextToFile() function allows you to print the
  5180.          contents of a window to a file.  Here is the prototype:
  5181.  
  5182.          int WindowWriteTextToFile(WPOINTER w, char *filename,
  5183.                                    int mode)
  5184.  
  5185.          The first argument is the window.  The second argument is the
  5186.          file name.  This file can be any of the DOS filenames ("con",
  5187.          "prn", "aux", etc.).  The file specified by filename must be
  5188.          closed before calling WindowWriteTextToFile(), and the file
  5189.          handle is automatically closed before exiting
  5190.          WindowWriteTextToFile().
  5191.  
  5192.          The last argument is the mode switch.  If mode is 1, a
  5193.          newline ('\n') is written to the file after each line of the
  5194.          window is written to the file.  If mode is 0, no newline
  5195.          character is written.
  5196.  
  5197.  
  5198.  
  5199.          Example:
  5200.  
  5201.          #include "window.h"
  5202.          #include <stdio.h>
  5203.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5204.  
  5205.          WPOINTER w;
  5206.          FILE *outfile;
  5207.          char *filename = "wintext";
  5208.          char *filename2 = "wintext2";
  5209.  
  5210.          main()
  5211.          {
  5212.            int i;
  5213.            WindowInitializeSystem();
  5214.            WindowSaveInitial(0);
  5215.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  5216.            WindowOpen(w);
  5217.            WindowDisplay(w,1,NOEFFECT);
  5218.            for (i=1;i<=10;i++)
  5219.              WindowWriteString(w,"Hello World!!",i,1);
  5220.            GET_KEY();
  5221.            WindowWriteTextToFile(w,filename,1);  /* use newlines */
  5222.            WindowWriteTextToFile(w,filename2,0); /* no newlines */
  5223.          }
  5224.  
  5225.  
  5226.  
  5227.          Page 73          The C Window Library               Page 73
  5228.  
  5229.  
  5230.          The example above illustrates two calls to
  5231.          WindowWriteTextToFile().  The first call writes the contents
  5232.          of the window w to a file called "wintext".  Note that the
  5233.          mode parameter for the first call is 1.  This will cause '\n'
  5234.          to be written to the file for each line of the window.  The
  5235.          second call writes the window text to a file call "wintest2",
  5236.          with the mode parameter being 0 (no '\n').
  5237.  
  5238.          Please note that WindowWriteTextToFile() does not check if
  5239.          the file already exists, so be careful that you do not
  5240.          replace files that are important to you.
  5241.  
  5242.  
  5243.  
  5244.          If there are no errors, WindowWriteTextToFile() returns
  5245.          NO_ERROR.
  5246.  
  5247.          If there are errors, WindowWriteTextToFile() will return one
  5248.          of the following:
  5249.  
  5250.  
  5251.          BAD_WINDOW if the window does not exist.
  5252.  
  5253.          WINDOW_NOT_OPEN if the window is not open for writing (use
  5254.          WindowOpen())
  5255.  
  5256.          FILE_CANT_OPEN if the file specified by filename cannot be
  5257.          open.
  5258.  
  5259.          FILE_CANT_CLOSE if the file specified by filename cannot be
  5260.          closed.
  5261.  
  5262.  
  5263.  
  5264.  
  5265.  
  5266.  
  5267.  
  5268.  
  5269.  
  5270.  
  5271.  
  5272.  
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278.  
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285.  
  5286.  
  5287.          Page 74          The C Window Library               Page 74
  5288.  
  5289.                           SHADOWING WINDOWS
  5290.                           -----------------
  5291.  
  5292.          With The C Window Library, you can place shadows on the
  5293.          windows created.  Shadows create a nice effect when displayed
  5294.          with the proper background color.  There are four positions
  5295.          where you can place a shadow on a window: the upper left
  5296.          corner of the window, the upper right corner, the lower left
  5297.          corner or the lower right corner.
  5298.  
  5299.          The shadow consists of two components.  One of these
  5300.          components is the part of the shadow that is drawn either on
  5301.          the left or right side of the window.  You can control the
  5302.          width of this portion of the shadow.  The other component
  5303.          that makes up the shadow is the portion that is drawn either
  5304.          on top of or underneath a window.  You can control the height
  5305.          of this portion of the shadow.
  5306.  
  5307.          You can also control the shadows video attribute, as well as
  5308.          the character that makes up the shadow itself.  My suggestion
  5309.          is to use ASCII character 219 for the shadow character.
  5310.          Other ones that work well are ASCII 176, 178, and 178.
  5311.  
  5312.          Transparent shadows are also supported.
  5313.  
  5314.          You can place a shadow on a window at any time or take it off
  5315.          at any time.  The only restriction with the shadow is that
  5316.          the window's current position must have room to draw the
  5317.          shadow.
  5318.  
  5319.  
  5320.          WindowDrawShadow()
  5321.          ------------------
  5322.  
  5323.          The WindowDrawShadow() function places a shadow on a window.
  5324.          Here is the prototype:
  5325.  
  5326.          int WindowDrawShadow(WPOINTER w, int shadowpos, int width,
  5327.                               int height, int shadowchar,
  5328.                               int shadowattr, int transflag)
  5329.  
  5330.          The first argument is the window that the shadow will be
  5331.          drawn.  The second argument is the position of the shadow.
  5332.          There are four possible positions:
  5333.  
  5334.          SHADOWUPRIGHT - draws shadow on upper right corner of the
  5335.                          window.
  5336.  
  5337.          SHADOWUPLEFT -  draws shadow on upper left corner of the
  5338.                          window.
  5339.  
  5340.          SHADOWLOWRIGHT - draws shadow on lower right corner of
  5341.                           window.
  5342.  
  5343.          SHADOWLOWLEFT - draws shadow on lower left corner of window.
  5344.  
  5345.  
  5346.  
  5347.          Page 75          The C Window Library               Page 75
  5348.  
  5349.          The third argument is the width of the strip of the shadow
  5350.          that is drawn on the right or left side of the window.  The
  5351.          fourth argument is the height of the strip of the shadow that
  5352.          is drawn on top or underneath the window.  The fifth argument
  5353.          is the character to use for the shadow.  The sixth argument
  5354.          is the attribute to use for the shadow.  The last argument is
  5355.          a flag denoting whether the shadow should be a transparent
  5356.          shadow.  If the flag is 0, the shadow is solid, otherwise the
  5357.          shadow is transparent.
  5358.  
  5359.  
  5360.          Example:
  5361.  
  5362.          #include "window.h"
  5363.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5364.          #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)
  5365.          #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  5366.          #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  5367.          #define REVERSE      CREATE_VIDEO_ATTRIBUTE(white,black)
  5368.  
  5369.          main()
  5370.          {
  5371.            WPOINTER w0,w1;
  5372.            WindowInitializeSystem();
  5373.            WindowSaveInitial(0);
  5374.            w0 = WindowInitialize(NOBORDER,1,1,80,25,REVERSE,REVERSE,0);
  5375.            WindowOpen(w0);
  5376.            WindowDisplay(w0,1,NOEFFECT);
  5377.            w1 = WindowInitialize(BORDER,5,5,40,15,BLUEONBLACK,
  5378.                                  REDONBLACK,SINGLEBOX);
  5379.            WindowOpen(w1);
  5380.            WindowDrawShadow(w1,SHADOWUPLEFT,2,1,219,REVERSE,0);
  5381.            WindowDisplay(w1,1,NOEFFECT);
  5382.            WindowWriteString(w1,"Press a key to move shadow",1,1);
  5383.            GET_KEY();
  5384.            WindowDrawShadow(w1,SHADOWUPRIGHT,2,1,219,REVERSE,0);
  5385.            WindowWriteString(w1,"Press a key again",2,1);
  5386.            GET_KEY();
  5387.            WindowDrawShadow(w1,SHADOWLOWLEFT,2,1,219,REVERSE,0);
  5388.            WindowWriteString(w1,"Press a key once more",3,1);
  5389.            GET_KEY();
  5390.            WindowDrawShadow(w1,SHADOWLOWRIGHT,2,1,219,REVERSE,0);
  5391.            GET_KEY();
  5392.            WindowClose(w1,NOEFFECT);
  5393.            WindowClose(w0,NOEFFECT);
  5394.          }
  5395.  
  5396.          The above example illustrates the use of WindowDrawShadow().
  5397.  
  5398.          If there is no error, WindowDrawShadow() returns NO_ERROR.
  5399.  
  5400.          If there are errors, WindowDrawShadow() returns one of the
  5401.          following:
  5402.  
  5403.          BAD_WINDOW if the window does not exist.
  5404.  
  5405.  
  5406.  
  5407.          Page 76          The C Window Library               Page 76
  5408.  
  5409.          WINDOW_BOUND if a shadow could not be drawn because of window
  5410.          location and the height and/or width of the shadow will
  5411.          exceed the screen edges.
  5412.  
  5413.  
  5414.  
  5415.  
  5416.          WindowRemoveShadow()
  5417.          --------------------
  5418.  
  5419.          The WindowRemoveShadow() function removes a shadow from a
  5420.          window, and takes a single argument, namely the window
  5421.          pointer.  Here is the prototype:
  5422.  
  5423.                    int WindowRemoveShadow(WPOINTER w)
  5424.  
  5425.          If there are no errors or the window does not have a shadow,
  5426.          WindowRemoveShadow() returns NO_ERROR.
  5427.  
  5428.          If there are errors, WindowRemoveShadow() returns the
  5429.          following value:
  5430.  
  5431.          BAD_WINDOW if the window does not exist.
  5432.  
  5433.  
  5434.  
  5435.  
  5436.  
  5437.  
  5438.  
  5439.  
  5440.  
  5441.  
  5442.  
  5443.  
  5444.  
  5445.  
  5446.  
  5447.  
  5448.  
  5449.  
  5450.  
  5451.  
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464.  
  5465.  
  5466.  
  5467.          Page 77          The C Window Library               Page 77
  5468.  
  5469.                           SEE-THRU WINDOWS
  5470.                           ----------------
  5471.  
  5472.          You can create windows that have borders, but do not
  5473.          overwrite the screen underneath.  These windows are called
  5474.          see-thru windows.
  5475.  
  5476.          When creating see-thru windows the WindowMakeSeeThru()
  5477.          function is used to make a defined window a see-thru window.
  5478.  
  5479.          You can turn a non-seethru window into a seethru window and
  5480.          vice-versa by calling the WindowMakeNormal() function.
  5481.  
  5482.  
  5483.  
  5484.          WindowMakeSeeThru()
  5485.          -------------------
  5486.  
  5487.          The WindowMakeSeeThru() function turns a normal window into a
  5488.          see-thru window.  Here is a prototype:
  5489.  
  5490.                        int WindowMakeSeeThru(WPOINTER w)
  5491.  
  5492.          The only argument is the window pointer.  You can make a
  5493.          window a see-thru window at any time, including if it is
  5494.          hidden.  If there is text in the normal window before making
  5495.          it a see-thru window, the text is retained.  If text is
  5496.          written to a see-thru window, the text is written to the
  5497.          window's internal write buffer, but is not displayed on the
  5498.          screen.
  5499.  
  5500.  
  5501.          Example:
  5502.  
  5503.            #include "window.h"
  5504.  
  5505.            #define NORM            CREATE_VIDEO_ATTRIBUTE(black,white)
  5506.  
  5507.            WPOINTER w;
  5508.  
  5509.            main()
  5510.            {
  5511.              WindowInitializeSystem();
  5512.              WindowSaveInitial(0);
  5513.              w = WindowInitialize(BORDER,1,1,20,5,NORM,NORM,SINGLEBOX);
  5514.              WindowOpen(w);
  5515.              WindowDisplay(w,1,NOEFFECT);
  5516.              GET_KEY();
  5517.              WindowMakeSeeThru(w);
  5518.              GET_KEY();
  5519.              WindowFree(w,NOEFFECT);
  5520.            }
  5521.  
  5522.  
  5523.          The example above displays a normal window, and then turns
  5524.  
  5525.  
  5526.  
  5527.          Page 78          The C Window Library               Page 78
  5528.  
  5529.          the normal window into a see-thru window when a key is
  5530.          pressed.
  5531.  
  5532.          If there are no errors, WindowMakeSeeThru() returns NO_ERROR.
  5533.  
  5534.          If there are errors, WindowMakeSeeThru() returns the
  5535.          following value:
  5536.  
  5537.          BAD_WINDOW if the window does not exist.
  5538.  
  5539.  
  5540.  
  5541.  
  5542.          WindowMakeNormal()
  5543.          ------------------
  5544.  
  5545.          The WindowMakeNormal() function turns a see-thru window into
  5546.          a normal text window.  Any text that may have been written to
  5547.          the window will be displayed.  Here is the prototype:
  5548.  
  5549.                      int WindowMakeNormal(WPOINTER w)
  5550.  
  5551.          Example:
  5552.  
  5553.            #include "window.h"
  5554.  
  5555.            #define NORM            CREATE_VIDEO_ATTRIBUTE(black,white)
  5556.  
  5557.            WPOINTER w;
  5558.  
  5559.            main()
  5560.            {
  5561.              WindowInitializeSystem();
  5562.              WindowSaveInitial(0);
  5563.              w = WindowInitialize(BORDER,1,1,20,5,NORM,NORM,SINGLEBOX);
  5564.              WindowOpen(w);
  5565.              WindowDisplay(w,1,NOEFFECT);
  5566.              GET_KEY();
  5567.              WindowMakeSeeThru(w);
  5568.              GET_KEY();
  5569.              WindowMakeNormal(w);
  5570.            }
  5571.  
  5572.  
  5573.          The example above demonstrates the WindowMakeNormal()
  5574.          function.
  5575.  
  5576.          If there are no errors, WindowMakeNormal() returns NO_ERROR.
  5577.  
  5578.          If there are errors, WindowMakeNormal() returns the following
  5579.          value:
  5580.  
  5581.          BAD_WINDOW if the window does not exist.
  5582.  
  5583.  
  5584.  
  5585.  
  5586.  
  5587.          Page 79          The C Window Library               Page 79
  5588.  
  5589.                      MOVING AND SLIDING WINDOWS
  5590.                      --------------------------
  5591.  
  5592.          With The C Window Library, you can move and slide windows on
  5593.          the screen.  The functions that perform this are the
  5594.          WindowMove() and WindowSlide().
  5595.  
  5596.  
  5597.          WindowMove()
  5598.          ------------
  5599.  
  5600.          The WindowMove() function moves a window to a new location on
  5601.          the screen.  Here is the prototype:
  5602.  
  5603.                 int WindowMove(WPOINTER w, int row, int col)
  5604.  
  5605.          The first argument is the window.  The second and third
  5606.          arguments are the row and column on the physical screen to
  5607.          place the upper left hand corner of the window.  Note that
  5608.          row and column are screen relative coordinates, not window
  5609.          relative.  This is one of the few functions where row and
  5610.          column denote a screen relative coordinate and not a window
  5611.          relative coordinate.
  5612.  
  5613.          If the row and/or column is out of bounds, the window is
  5614.          moved as far as possible.
  5615.  
  5616.          Example:
  5617.  
  5618.          #include "window.h"
  5619.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5620.  
  5621.          #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)
  5622.  
  5623.          main()
  5624.          {
  5625.            WPOINTER w;
  5626.            WindowInitializeSystem();
  5627.            WindowSaveInitial(0);
  5628.            w = WindowInitialize(BORDER,1,1,30,15,BLUEONBLACK,NORM,
  5629.                                 SINGLEBOX);
  5630.            WindowOpen(w);
  5631.            WindowWriteString(w,"Press a key to move me",1,1);
  5632.            WindowDisplay(w,1,NOEFFECT);
  5633.            GET_KEY();
  5634.            WindowMove(w,12,14);
  5635.  
  5636.          }
  5637.  
  5638.          The example above moves the window from its original position
  5639.          (1,1) to (12,14).
  5640.  
  5641.          If there is no error WindowMove() returns NO_ERROR.
  5642.  
  5643.          If there are errors WindowMove() returns the following value:
  5644.          BAD_WINDOW if the window does not exist.
  5645.  
  5646.  
  5647.          Page 80          The C Window Library               Page 80
  5648.  
  5649.          WindowSlide()
  5650.          -------------
  5651.  
  5652.          The WindowSlide() function "slides" a window from one
  5653.          position on the screen to another.  Here is the prototype:
  5654.  
  5655.              int WindowSlide(WPOINTER w, int direction, int units)
  5656.  
  5657.          The first argument is the window.  The second argument tells
  5658.          in which direction to move the window, either up, down, left,
  5659.          or right.  The constants to use for up, down, left, and right
  5660.          are UP, DOWN, LEFT, and RIGHT, respectively.  The third
  5661.          argument tells how many rows or columns to move the window.
  5662.          If the number of units will cause the window to exceed the
  5663.          boundaries of the screen, the window is moved as far as
  5664.          possible.
  5665.  
  5666.  
  5667.          Example:
  5668.  
  5669.          #include "window.h"
  5670.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5671.  
  5672.          #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)
  5673.  
  5674.  
  5675.          main()
  5676.          {
  5677.            WPOINTER w;
  5678.            WindowInitializeSystem();
  5679.            WindowSaveInitial(0);
  5680.            w = WindowInitialize(BORDER,1,1,30,10,BLUEONBLACK,NORM,
  5681.                                 SINGLEBOX);
  5682.            WindowOpen(w);
  5683.            WindowWriteString(w,"Press a key to slide right",1,1);
  5684.            WindowDisplay(w,1,NOEFFECT);
  5685.            GET_KEY();
  5686.            WindowSlide(w,RIGHT,20);
  5687.            WindowWriteString(w,"Press a key to slide down",2,1);
  5688.            GET_KEY();
  5689.            WindowSlide(w,DOWN,10);
  5690.            WindowWriteString(w,"Press a key to slide left",3,1);
  5691.            GET_KEY();
  5692.            WindowSlide(w,LEFT,20);
  5693.            WindowWriteString(w,"Press a key to slide up",4,1);
  5694.            GET_KEY();
  5695.            WindowSlide(w,UP,20);
  5696.          }
  5697.  
  5698.  
  5699.          The example above illustrates how to use the WindowSlide()
  5700.          function.
  5701.  
  5702.          The return values for WindowSlide() are the same as
  5703.          WindowMove().
  5704.  
  5705.  
  5706.  
  5707.          Page 81          The C Window Library               Page 81
  5708.  
  5709.                     CURSOR POSITIONING IN WINDOWS
  5710.                     -----------------------------
  5711.  
  5712.          You can change the position of the cursor and its shape in
  5713.          the windows you create with The C Window Library.
  5714.  
  5715.  
  5716.  
  5717.          Cursor Maintenance in The C Window Library
  5718.          ------------------------------------------
  5719.  
  5720.          As was stated before, The C Window Library can write to any
  5721.          window at any time.  This makes the question "which window
  5722.          owns the cursor?" a hard question to answer.  One method is
  5723.          that the window being updated either by writing text,
  5724.          clearing, etc. should have immediate control of the cursor.
  5725.          The approach The C Window Library has taken is that the
  5726.          top-most window always has control of the cursor.  The
  5727.          topmost window is determined by its rank number.  Windows
  5728.          with low rank numbers overlay windows with higher rank
  5729.          numbers.
  5730.  
  5731.  
  5732.  
  5733.          Creating Cursor Shapes
  5734.          ----------------------
  5735.  
  5736.          The C Window Library has three pre-defined cursor shapes;
  5737.          INVISIBLE, THIN, and BLOCK.  An INVISIBLE cursor hides the
  5738.          cursor, a BLOCK shape creates a "fat" cursor, and THIN
  5739.          creates a thin cursor.  If you want to define your own cursor
  5740.          shapes, use the CREATE_CURSOR_SHAPE() macro.  This macro
  5741.          takes two arguments the first argument is the beginning scan
  5742.          line, and the second argument is the ending scan line.  Scan
  5743.          lines determine the height of the cursor.  For monochrome
  5744.          systems, the scan lines range from 0 to 13.  In a color
  5745.          system, the scan lines range from 0 to 7.  A THIN cursor has
  5746.          its starting scan line at 6 and its ending scan line at 7 for
  5747.          color systems, and for monochrome systems, the starting scan
  5748.          line is 11 and its ending scan line is at 12.  If the
  5749.          starting scan line number is greater than the ending scan
  5750.          line number, the cursor takes on a 'double' cursor shape.
  5751.          Experiment with different starting and ending scan lines for
  5752.          the desired effect.
  5753.  
  5754.  
  5755.  
  5756.          WindowChangeCursor()
  5757.          --------------------
  5758.  
  5759.          The WindowChangeCursor() function changes the shape of the
  5760.          cursor in a window.  Here is the prototype:
  5761.  
  5762.                 int WindowChangeCursor(WPOINTER w, int shape)
  5763.  
  5764.  
  5765.  
  5766.  
  5767.          Page 82          The C Window Library               Page 82
  5768.  
  5769.          The first argument is the window.  The second argument is the
  5770.          desired cursor shape.
  5771.  
  5772.  
  5773.          Example:
  5774.  
  5775.          #include "window.h"
  5776.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5777.  
  5778.  
  5779.  
  5780.          WPOINTER w;
  5781.  
  5782.          main()
  5783.          {
  5784.            WindowInitializeSystem();
  5785.            WindowSaveInitial(0);
  5786.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5787.            WindowOpen(w);
  5788.            WindowDisplay(w,1,NOEFFECT);
  5789.            WindowWriteString(w,"Press a key to change cursor",1,1);
  5790.            GET_KEY();
  5791.            WindowChangeCursor(w,BLOCK);
  5792.            WindowWriteString(w,"Press a key to change cursor again",
  5793.                              2,1);
  5794.            GET_KEY();
  5795.            WindowChangeCursor(w,INVISIBLE);
  5796.            WindowWriteString(w,"Press a key to change cursor again",
  5797.                              3,1);
  5798.            GET_KEY();
  5799.            WindowChangeCursor(w,THIN);
  5800.          }
  5801.  
  5802.  
  5803.          If there are no errors, WindowChangeCursor() returns
  5804.          NO_ERROR.
  5805.  
  5806.          If there are errors, WindowChangeCursor() returns the
  5807.          following value:
  5808.  
  5809.          BAD_WINDOW if the window does not exist.
  5810.  
  5811.  
  5812.  
  5813.  
  5814.  
  5815.          WindowMoveCursor()
  5816.          ------------------
  5817.  
  5818.          The WindowMoveCursor() functions moves the cursor in a window
  5819.          to a new location in the window.  Here is the prototype:
  5820.  
  5821.  
  5822.             int WindowMoveCursor(WPOINTER w, int row, int col)
  5823.  
  5824.  
  5825.  
  5826.  
  5827.          Page 83          The C Window Library               Page 83
  5828.  
  5829.          The first argument is the window, and the second and third
  5830.          arguments are the new (row,col) position in the window to
  5831.          place the cursor.
  5832.  
  5833.  
  5834.  
  5835.          Example:
  5836.  
  5837.          #include "window.h"
  5838.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5839.  
  5840.          WPOINTER w;
  5841.  
  5842.          main()
  5843.          {
  5844.            WindowInitializeSystem();
  5845.            WindowSaveInitial(0);
  5846.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5847.            WindowOpen(w);
  5848.            WindowDisplay(w,1,NOEFFECT);
  5849.            WindowWriteString(w,"Press a key to move cursor",1,1);
  5850.            GET_KEY();
  5851.            WindowMoveCursor(w,7,5);
  5852.          }
  5853.  
  5854.  
  5855.          If there are no errors, WindowMoveCursor() returns NO_ERROR.
  5856.          If there are errors, WindowMoveCursor() returns the following
  5857.          values:
  5858.  
  5859.          BAD_WINDOW if the window does not exist.
  5860.  
  5861.          WINDOW_BOUND if either new row or column number is out of the
  5862.          boundaries of the window.
  5863.  
  5864.  
  5865.  
  5866.  
  5867.          WindowGetCursorShape()
  5868.          ----------------------
  5869.  
  5870.          The WindowGetCursorShape() function returns the starting and
  5871.          ending scan lines of the cursor defined in a window.  Here is
  5872.          the prototype:
  5873.  
  5874.  
  5875.          int WindowGetCursorShape(WPOINTER w, int *startline,
  5876.                                   int *endline)
  5877.  
  5878.          The startline and endline arguments are pointers to integers
  5879.          that will contain the starting and ending scan lines of the
  5880.          cursor when WindowGetCursorShape() returns.
  5881.  
  5882.  
  5883.  
  5884.  
  5885.  
  5886.  
  5887.          Page 84          The C Window Library               Page 84
  5888.  
  5889.          Example:
  5890.  
  5891.          #include "window.h"
  5892.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5893.  
  5894.          WPOINTER w;
  5895.  
  5896.          main()
  5897.          {
  5898.            int startline,endline;
  5899.            WindowInitializeSystem();
  5900.            WindowSaveInitial(0);
  5901.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5902.            WindowOpen(w);
  5903.            WindowDisplay(w,1,NOEFFECT);
  5904.            WindowGetCursorShape(w,&startline,&endline);
  5905.            WindowPrintf(w,
  5906.            "The starting scan line is %d\nThe ending scan line is %d",
  5907.                         startline,endline);
  5908.          }
  5909.  
  5910.          The example above calls WindowGetCursorShape() and uses
  5911.          WindowPrintf() to print what the starting and ending scan
  5912.          lines are.
  5913.  
  5914.          If there are no errors, WindowGetCursorShape() returns
  5915.          NO_ERROR.
  5916.  
  5917.          If there are errors, WindowGetCursorShape() returns the
  5918.          following values:
  5919.  
  5920.          BAD_WINDOW if the window does not exist.
  5921.  
  5922.  
  5923.  
  5924.  
  5925.  
  5926.          WindowGetCursorPosition()
  5927.          -------------------------
  5928.  
  5929.          The WindowGetCursorPosition() function gives the current row
  5930.          and column of the cursor in a window.  Here is the prototype:
  5931.  
  5932.          int WindowGetCursorPosition(WPOINTER w, int *row, int *col)
  5933.  
  5934.          The row and col arguments are pointers to integers that will
  5935.          contain the row and column of the cursor after
  5936.          WindowGetCursorPosition() is called.
  5937.  
  5938.  
  5939.  
  5940.          Example:
  5941.  
  5942.          #include "window.h"
  5943.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5944.  
  5945.  
  5946.  
  5947.          Page 85          The C Window Library               Page 85
  5948.  
  5949.  
  5950.          WPOINTER w;
  5951.  
  5952.          main()
  5953.          {
  5954.            int row,col;
  5955.            WindowInitializeSystem();
  5956.            WindowSaveInitial(0);
  5957.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5958.            WindowOpen(w);
  5959.            WindowDisplay(w,1,NOEFFECT);
  5960.            WindowMoveCursor(w,7,4);
  5961.            WindowGetCursorPosition(w,&row,&col);
  5962.            WindowPrintf(w,
  5963.                         "The row of the cursor is %d\n"
  5964.                         "The column of the cursor is %d", row,col);
  5965.          }
  5966.  
  5967.          If there are no errors, WindowGetCursorPosition() returns
  5968.          NO_ERROR.
  5969.  
  5970.          If there are errors, WindowGetCursorPosition() returns the
  5971.          following value:
  5972.  
  5973.          BAD_WINDOW if the window does not exist.
  5974.  
  5975.  
  5976.  
  5977.  
  5978.  
  5979.  
  5980.  
  5981.  
  5982.  
  5983.  
  5984.  
  5985.  
  5986.  
  5987.  
  5988.  
  5989.  
  5990.  
  5991.  
  5992.  
  5993.  
  5994.  
  5995.  
  5996.  
  5997.  
  5998.  
  5999.  
  6000.  
  6001.  
  6002.  
  6003.  
  6004.  
  6005.  
  6006.  
  6007.          Page 86          The C Window Library               Page 86
  6008.  
  6009.               GETTING WHICH WINDOW OCCUPIES A LOCATION
  6010.               ----------------------------------------
  6011.  
  6012.          You can determine the WPOINTER which occupies a location on
  6013.          the screen.  If you have multiple windows displayed, this can
  6014.          be very useful if you have overlaps and want to know which
  6015.          window is visible in a given screen location.
  6016.  
  6017.  
  6018.          WindowWhich()
  6019.          -------------
  6020.  
  6021.          The WindowWhich() function determines which window is visible
  6022.          on a given screen location.  Here is the prototype:
  6023.  
  6024.               WPOINTER WindowWhich(int row, int col, int page)
  6025.  
  6026.          Note that WindowWhich() returns a WPOINTER.  The arguments
  6027.          row and col are absolute screen coordinates.  The last
  6028.          argument, page, is the video page to use when determining
  6029.          which window lies in position (row,col).  The WPOINTER that
  6030.          is returned is the WPOINTER that occupies the specified
  6031.          screen location.
  6032.  
  6033.  
  6034.          #include "window.h"
  6035.  
  6036.          WPOINTER w1, w2, w3, w4, w5;
  6037.          main()
  6038.          {
  6039.             /* ... Assume everything including windows have been
  6040.                    initialized and opened           */
  6041.  
  6042.            if (WindowWhich(4,7,0) == w1)
  6043.            {
  6044.              /* some part of w1 is visible on row 4 column 7 of the
  6045.                 screen (video page 0) */
  6046.            }
  6047.          }
  6048.  
  6049.  
  6050.           The above example calls WindowWhich to determine if w1
  6051.           is visible on position (4,7) of video page 0.
  6052.           Refer to the INTRODUCTION on video pages.
  6053.  
  6054.           If there is no window visible for a given screen location,
  6055.           WIN_NULL_PTR is returned.  The base screen will always
  6056.           return a WIN_NULL_PTR.
  6057.  
  6058.  
  6059.  
  6060.  
  6061.  
  6062.  
  6063.  
  6064.  
  6065.  
  6066.  
  6067.          Page 87          The C Window Library               Page 87
  6068.  
  6069.                      GETTING INPUT FROM WINDOWS
  6070.                      --------------------------
  6071.  
  6072.          With The C Window Library, you can read input from windows.
  6073.          The input can be simple string input, or inputting strings
  6074.          with a character mask.  There is also support for scrolling
  6075.          input fields.
  6076.  
  6077.  
  6078.  
  6079.  
  6080.          Input Manager
  6081.          -------------
  6082.  
  6083.          The input manager are functions internal in The C Window
  6084.          Library that control editing, checking for invalid
  6085.          characters, cursor movement, etc.
  6086.  
  6087.  
  6088.          Regular Expressions
  6089.          -------------------
  6090.  
  6091.          With The C Window Library, you specify exactly what
  6092.          characters are to be expected for every input position by
  6093.          using a special string of characters called a regular
  6094.          expression (a pattern matching string).
  6095.  
  6096.          Note:
  6097.          For those who are familiar with regular expressions, there is
  6098.          a difference between the regular expressions you will see
  6099.          here, and the regular expressions you will find in certain
  6100.          text editors, or in computer language syntax definitions.
  6101.          One major difference is that there are no wild cards denoting
  6102.          an arbitrary number of repeated characters (which is usually
  6103.          denoted by a '*' or a '+'), and there are no 'match begin of
  6104.          string' and 'match end of string' functions.
  6105.  
  6106.  
  6107.  
  6108.          An example of a regular expression would be the string
  6109.          "[A-Z]" which means only those characters that are between  A
  6110.          and Z, inclusive, are to be accepted as valid input
  6111.          characters.  Of course, the ASCII collating sequence is used.
  6112.  
  6113.          The following characters have special meanings in regular
  6114.          expressions:
  6115.  
  6116.           Character              Purpose
  6117.           ---------              -------
  6118.  
  6119.           Forward Slash (/)      Removes the special meaning of the
  6120.                                  next character in the regular
  6121.                                  expression.
  6122.  
  6123.  
  6124.  
  6125.  
  6126.  
  6127.          Page 88          The C Window Library               Page 88
  6128.  
  6129.           Brackets ([])          Encloses a set of characters to be
  6130.                                  matched with the current character
  6131.                                  entered at the keyboard.  There are
  6132.                                  other special symbols that can appear
  6133.                                  in brackets:
  6134.                                  -----------------------------------
  6135.  
  6136.                                  Carat (^)    This symbol states that
  6137.                                               the character entered at
  6138.                                               the keyboard must not
  6139.                                               match any character in
  6140.                                               the brackets.  The carat
  6141.                                               must be the first
  6142.                                               character after the left
  6143.                                               bracket ([), otherwise
  6144.                                               the carat is taken
  6145.                                               literally as just
  6146.                                               another character.
  6147.  
  6148.                                  Dash  (-)    Matches character
  6149.                                               entered at keyboard with
  6150.                                               characters in ASCII
  6151.                                               order between
  6152.                                               (inclusive) the
  6153.                                               characters on either
  6154.                                               side of the dash.
  6155.  
  6156.                                  Dot   (.)    Matches any displayable
  6157.                                               ASCII character.
  6158.  
  6159.          There are two categories of regular expressions; namely
  6160.          simple and complex.  Simple regular expressions only specify
  6161.          a single character to be entered from the keyboard, while
  6162.          complex regular expressions specify that more than a single
  6163.          character must be entered from the keyboard.
  6164.  
  6165.          Here are examples of simple regular expressions:
  6166.  
  6167.  
  6168.  
  6169.               Simple
  6170.          Regular Expression              What will be accepted
  6171.          ------------------              ---------------------
  6172.  
  6173.               [0-9]                      Accept any single digit
  6174.                                          character.
  6175.  
  6176.               [3-7]                      Accept single digit character
  6177.                                          between '3' and '7'
  6178.                                          inclusive.
  6179.  
  6180.               [A-Z]                      Accept a letter between 'A'
  6181.                                          and 'Z' inclusive.
  6182.  
  6183.               [A-Za-z]                   Accept a letter between 'A'
  6184.  
  6185.  
  6186.  
  6187.          Page 89          The C Window Library               Page 89
  6188.  
  6189.                                          and 'Z' or a letter between
  6190.                                          'a' and 'z'.
  6191.  
  6192.  
  6193.               [ABCD]                     Accept either 'A', 'B', 'C',
  6194.                                          or 'D'.
  6195.  
  6196.               [A-Za-z0-9]                Accept anything between 'A'
  6197.                                          and 'Z', or 'a' and 'z', or
  6198.                                          '0' and '9'
  6199.  
  6200.               [0-9ABCD]                  Accept '0' thru '9', 'A',
  6201.                                          'B', 'C', or 'D'.
  6202.  
  6203.               [^A]                       Accept any character except
  6204.                                          'A'.
  6205.  
  6206.               [^A-Z]                     Accept any character except
  6207.                                          the characters between 'A'
  6208.                                          and 'Z' (inclusive).
  6209.  
  6210.               [A-/[]                     Accept any character between
  6211.                                          'A' and '[', inclusive.
  6212.                                          Please note the use of the
  6213.                                          forward slash to denote that
  6214.                                          the left bracket has no
  6215.                                          special meaning.
  6216.  
  6217.               [A Z]                      Accept 'A', the space
  6218.                                          character, or 'Z'.
  6219.  
  6220.               [A/-Z]                     Accept 'A', the minus (-), or
  6221.                                          'Z'.
  6222.  
  6223.               [/-///]]                   Accept the minus (-), the
  6224.                                          forward slash (/), or the
  6225.                                          right bracket (]).
  6226.  
  6227.               [!-&]                      Accept the ASCII characters
  6228.                                          between '!' and '&',
  6229.                                          inclusive.
  6230.  
  6231.               A                          Accept the letter 'A'.  Note
  6232.                                          that this is equivalent to
  6233.                                          [A].
  6234.  
  6235.               [9]                        Accept the digit '9'.
  6236.  
  6237.               .                          Accept any character.
  6238.  
  6239.               []                         Accept no key and call user
  6240.                                          defined function (explained
  6241.                                          later in the UNDEFINED
  6242.                                          KEYSTROKE PROCESSING
  6243.                                          section).
  6244.  
  6245.  
  6246.  
  6247.          Page 90          The C Window Library               Page 90
  6248.  
  6249.          Remember, all of the above expressions process only one
  6250.          character entered at the keyboard, even though some of the
  6251.          expressions can accept a variety of characters.
  6252.  
  6253.          As you can see there are many possibilities you can make up.
  6254.          However the above forms of a regular expressions only work
  6255.          for one character entered at the keyboard.  What if you want
  6256.          to enter a persons name, address, social security number
  6257.          etc.?  You can concatenate (glue together) the regular
  6258.          expressions above to form a chain of regular expressions.
  6259.          This resulting chain is called a complex regular expression.
  6260.          Here are a few examples of complex regular expressions:
  6261.  
  6262.          Regular Expression              What will be accepted
  6263.          ------------------              ---------------------
  6264.             [A-Z][0-9]                   The first character entered
  6265.                                          must be between 'A' and 'Z'.
  6266.                                          The second character entered
  6267.                                          must be between '0' and '9'.
  6268.  
  6269.             [A-Z][^A-Z][0-9]             Enter three characters.  The
  6270.                                          first must be between 'A' and
  6271.                                          'Z'.  The second can be any
  6272.                                          character except anything
  6273.                                          between 'A' and 'Z', and the
  6274.                                          third character must be
  6275.                                          between '0' and '9'.
  6276.  
  6277.          [1-9][0-9][0-9][0-9][0-9]       Enter five characters.  The
  6278.                                          first must be between '1' and
  6279.                                          '9'.  The other four
  6280.                                          characters must be between
  6281.                                          '0' and '9'.
  6282.  
  6283.          [A-Z][][0-9]                    The first character must be
  6284.                                          between 'A' and 'Z', the
  6285.                                          second input position calls a
  6286.                                          user defined function
  6287.                                          (explained in UNDEFINED
  6288.                                          KEYSTROKE PROCESSING), and
  6289.                                          the third character must be
  6290.                                          between '0' and '9'.
  6291.  
  6292.          As you can see again, the strings can get pretty long if you
  6293.          wanted to setup a thirty character input specification, for
  6294.          instance, a persons name.  To save time typing, you can use a
  6295.          multiplying factor in the regular expression.  A multiplying
  6296.          factor is a number that is placed before a simple regular
  6297.          expression to denote that the simple regular expression is
  6298.          repeated.
  6299.  
  6300.          Here are a few examples:
  6301.  
  6302.  
  6303.  
  6304.  
  6305.  
  6306.  
  6307.          Page 91          The C Window Library               Page 91
  6308.  
  6309.          Regular Expression    What will be accepted
  6310.          ------------------    ---------------------
  6311.  
  6312.            25[A-Z]             Enter twenty-five characters.  All the
  6313.                                characters must be between 'A' and 'Z'.
  6314.  
  6315.            10[0-9]             Enter ten characters.  All must be
  6316.                                between '0' and '9'.
  6317.  
  6318.            5[A-C] 3[1-3]       Enter nine characters. The first five
  6319.                                must be between 'A' and 'C' the sixth
  6320.                                must be the space character, and the
  6321.                                last three must be between '1' and '3'.
  6322.                                Please note the space embedded in the
  6323.                                string just before the multiplying
  6324.                                factor 3.
  6325.  
  6326.            [1-9]2X/[5[^A-Z]/1  Enter nine characters.  The first must
  6327.                                be between '1' and '9'.  The second and
  6328.                                third must be 'X'. The fourth is the
  6329.                                left bracket ([).  The next five
  6330.                                characters entered can be any character
  6331.                                except anything between 'A' and 'Z',
  6332.                                and the last character to accept is a
  6333.                                '1'.  Please note the use of the
  6334.                                forward slash just before the second
  6335.                                left bracket and just before the last
  6336.                                character ('1').  The forward slash
  6337.                                before the '1' makes sure the '1' is
  6338.                                not to be confused with a multiplying
  6339.                                factor of 1.
  6340.  
  6341.            [A-Z]/..            Enter three characters.  The first must
  6342.                                be between 'A' and 'Z'.  The second is
  6343.                                the '.', and the third is any
  6344.                                character.
  6345.  
  6346.            10[A-Z]3[]          Enter thirteen characters.  The first
  6347.                                ten must be between 'A' and 'Z', and
  6348.                                the last three input positions will
  6349.                                call a user defined undefined key
  6350.                                function (explained later in the
  6351.                                UNDEFINED KEYSTROKE PROCESSING
  6352.                                section).
  6353.  
  6354.          The only limitation to what you can do with regular
  6355.          expressions is that you cannot nest regular expressions.  For
  6356.          example:
  6357.  
  6358.                         [A-[A-Z]]     or     20[20[a-z]]
  6359.  
  6360.          It is ok to say [9-0] instead of [0-9].  They are both
  6361.          equivalent and both accepted by The C Window Library, so
  6362.          there is no need to know your ASCII table by heart, although
  6363.          it is advantageous to learn it if you want to create
  6364.  
  6365.  
  6366.  
  6367.          Page 92          The C Window Library               Page 92
  6368.  
  6369.          sophisticated regular expression strings.  You can even use
  6370.          the IBM extended character set (ASCII values above 127) in
  6371.          the regular expression string.
  6372.  
  6373.  
  6374.          Editing Input
  6375.          -------------
  6376.  
  6377.          The C library function gets(x), gets a string from the
  6378.          keyboard and points the character pointer x to the string.
  6379.          This function has limited editing capabilities.  The only
  6380.          keys recognized are the backspace, which serves as a
  6381.          destructive backspace (erases character immediately to the
  6382.          left) and the enter key when the user has typed in the
  6383.          desired string.  With The C Window Library, you have much
  6384.          more editing capabilities.
  6385.  
  6386.  
  6387.          The editing functions have the following default key values:
  6388.  
  6389.                                                               Mapped
  6390.            Function                               Key        Position
  6391.            --------                               ---         ------
  6392.          Move cursor left                    Left Arrow          0
  6393.          Move cursor right                   Right Arrow         1
  6394.          Delete character at cursor          Del (on keypad)     2
  6395.          Toggle Insert/Overwrite mode        Insert (on keypad)  3
  6396.          Erase Input and go to first column  ^E                  4
  6397.          Destructive backspace               Backspace           5
  6398.          Accept Input and return             Enter               6
  6399.          Accept default and return           Escape              7
  6400.          Go to first column                  Home                8
  6401.          Move cursor to last char. entered   End                 9
  6402.  
  6403.          Here is a list of what the key functions perform:
  6404.  
  6405.  
  6406.          Move cursor left - Moves the cursor left one character.  If
  6407.                             the beginning of the input field is
  6408.                             encountered the cursor is not moved.
  6409.  
  6410.          Move cursor right - Moves the cursor right one character.  If
  6411.                              the end of the input field is
  6412.                              encountered, the cursor is not moved.
  6413.  
  6414.          Delete character at cursor - Deletes the character at the
  6415.                                       position of the cursor.  If in
  6416.                                       insert mode, any input to the
  6417.                                       right of the cursor is moved one
  6418.                                       character to the left.  If in
  6419.                                       overwrite mode, no characters
  6420.                                       are moved.
  6421.  
  6422.          Toggle Insert/Overwrite Mode - toggles the input between
  6423.                                         insert and overwrite mode.  If
  6424.  
  6425.  
  6426.  
  6427.          Page 93          The C Window Library               Page 93
  6428.  
  6429.                                         in insert mode, the default
  6430.                                         cursor is an underline cursor.
  6431.                                         If in overwrite mode, the
  6432.                                         default cursor is a full
  6433.                                         block.
  6434.  
  6435.          Erase Input - Deletes all characters inputted and moves the
  6436.                        cursor to the first input position.
  6437.  
  6438.          Destructive Backspace - deletes the character immediately to
  6439.                                  the left of the cursor and moves the
  6440.                                  cursor to the left one character. If
  6441.                                  insert mode is on, the characters
  6442.                                  from the current cursor position to
  6443.                                  the end of the input field are also
  6444.                                  moved.
  6445.  
  6446.          Accept string - Accepts the string that is inputted and
  6447.                          returns the string.
  6448.  
  6449.          Accept default and return - Returns the default string given
  6450.                                      to the input routine.
  6451.  
  6452.          Go to first column - Moves cursor to the first input
  6453.          position.
  6454.  
  6455.          Go to last character - Moves cursor to the last character in
  6456.          the current input string.
  6457.  
  6458.          The keys used to perform these functions can be changed.  The
  6459.          mapped position is the offset in a table of key functions.
  6460.          By changing the value there, you can change the key used to
  6461.          perform these functions.  If you do want to change these
  6462.          keys, I recommend using the key definitions found in the
  6463.          keycodes.h file.  For example, if you wanted Control-B to be
  6464.          the destructive backspace you would do as follows:
  6465.  
  6466.                window_edit_key[5] = CTRLB;
  6467.  
  6468.          The table of key functions is stored in the array
  6469.          window_edit_key.  The CTRLB stands for Control-B and its
  6470.          definition is found in the keycodes.h file.  To totally
  6471.          undefine a key definition, assign a 0 to the desired array
  6472.          position in window_edit_key.  For example:
  6473.  
  6474.                window_edit_key[2] = 0;
  6475.  
  6476.          undefines the delete character at cursor definition.
  6477.  
  6478.          When changing keys, make sure that the definitions all have
  6479.          unique key combinations.  If you desire more keystrokes for a
  6480.          particular key function, see Undefined Keystroke Processing
  6481.          below.
  6482.  
  6483.  
  6484.  
  6485.  
  6486.  
  6487.          Page 94          The C Window Library               Page 94
  6488.  
  6489.          Last Key Value
  6490.          --------------
  6491.  
  6492.          On exit of any of the input functions, the global integer
  6493.          last_key_hit contains the ascii code (scan code) of the key
  6494.          that was used to exit the input function.
  6495.  
  6496.  
  6497.  
  6498.          Default Cursor Types and Editing Mode
  6499.          -------------------------------------
  6500.  
  6501.          By default, The C Window Library starts editing input in
  6502.          overstrike mode.  This means that characters are overwritten
  6503.          when the cursor is placed on a character.  The opposite of
  6504.          overstrike mode is insert mode, which pushes the characters
  6505.          to the right of the cursor over by one input position when a
  6506.          character is entered.  Also, the default cursor type for
  6507.          overstrike mode is a block cursor, and the default cursor for
  6508.          insert mode is a thin cursor.  You can change the startup
  6509.          mode, as well as the cursor types.
  6510.  
  6511.          The global variables default_cursor_type and
  6512.          default_cursor_mode store the values of the cursor shapes and
  6513.          the startup mode.
  6514.  
  6515.          The default_cursor_type is an array of two integers.  The
  6516.          OVERSTRIKEMODE constant is the position in the
  6517.          default_cursor_type array of where the overstrike shape of
  6518.          the cursor is stored.  The INSERTMODE constant is the
  6519.          position in default_cursor_type of where the insert shape of
  6520.          the cursor is stored.  Here is an example of how you would
  6521.          change the cursor types.
  6522.  
  6523.          #include "window.h"
  6524.  
  6525.          main()
  6526.          {
  6527.            WindowInitializeSystem();
  6528.            /*...*/                  /* Some code */
  6529.  
  6530.            default_cursor_type[OVERSTRIKEMODE] =
  6531.                                        CREATE_CURSOR_SHAPE(6,7);
  6532.            default_cursor_type[INSERTMODE] = THIN;
  6533.          }
  6534.  
  6535.          The CREATE_CURSOR_SHAPE() macro creates a cursor shape by
  6536.          using the first argument as the starting scan line of the
  6537.          cursor, and the second argument as the ending scan line.
  6538.          Refer to VIDEO MACROS section for more information on
  6539.          CREATE_CURSOR_SHAPE().  The THIN constant is a predefined
  6540.          constant that stands for a thin cursor.  The other predefined
  6541.          constants for cursor shapes are BLOCK and INVISIBLE.
  6542.  
  6543.          To change the startup mode when an input function is called,
  6544.  
  6545.  
  6546.  
  6547.          Page 95          The C Window Library               Page 95
  6548.  
  6549.          you must change the default_cursor_mode global variable.
  6550.          Here is how you would change the default mode:
  6551.  
  6552.          #include "window.h"
  6553.  
  6554.          main()
  6555.          {
  6556.            WindowInitializeSystem();
  6557.            /*...*/                  /* Some code */
  6558.            default_cursor_mode = OVERSTRIKEMODE;
  6559.          }
  6560.  
  6561.          Use the constants OVERSTRIKEMODE and INSERTMODE for the
  6562.          desired mode.
  6563.  
  6564.  
  6565.  
  6566.          Editing using a character mask
  6567.          ------------------------------
  6568.  
  6569.          The C Window Library also provides input functions that use
  6570.          character masks.  For example to enter a date, you might want
  6571.          the user to enter a date in MM-DD-YY format.  Instead of the
  6572.          user having to enter the hyphens, it would be advantageous if
  6573.          the input field already had hyphens, and the cursor will
  6574.          advance or back up to the next input position, jumping over
  6575.          any hyphens encountered.  You can accomplish this by using a
  6576.          character mask.
  6577.  
  6578.          The mask is a character string which is made up of
  6579.          displayable characters, and a special character used to
  6580.          denote an input position.  For example, a date mask would
  6581.          look like this:
  6582.  
  6583.                                 __-__-__
  6584.  
  6585.          The hyphens are displayed in the window, but the underscores
  6586.          are not displayed.  The underscores are used as a place
  6587.          holder, i.e. a place where input is expected.  By default,
  6588.          the input position character is an underscore, but you can
  6589.          change this.  Another example would be a social security
  6590.          mask:
  6591.  
  6592.                                ___-__-____
  6593.  
  6594.           a telephone mask:
  6595.                                   (___) ___-____ ext: ____
  6596.  
  6597.           another date mask:
  6598.                                   __/__/__
  6599.  
  6600.  
  6601.          If a character is deleted or inserted, the input manager is
  6602.          smart enough to move characters so that they do not clobber
  6603.          the characters that are not part of the input field.
  6604.  
  6605.  
  6606.  
  6607.          Page 96          The C Window Library               Page 96
  6608.  
  6609.          Editing Functions
  6610.          -----------------
  6611.  
  6612.          The following are functions that can be used to edit input
  6613.          with The C Window Library.
  6614.  
  6615.  
  6616.  
  6617.          WindowGetString()
  6618.          -----------------
  6619.  
  6620.          The WindowGetString() function gets a string from a window
  6621.          starting at a certain row and column of the window.  Here is
  6622.          the prototype:
  6623.  
  6624.          int WindowGetString(WPOINTER w, int row, int col,
  6625.                              char *buffer, int fillchar, int minchars,
  6626.                              int maxwidth, int options, int startpos,
  6627.                              char *regexp)
  6628.  
  6629.          The first argument is the window pointer.  The second and
  6630.          third arguments are the row and column of where the input
  6631.          begins.  The fourth argument is a pointer to a character
  6632.          buffer where the input characters will be stored.  Whatever
  6633.          null terminated string is stored in the character buffer
  6634.          prior to calling WindowGetString() will be used as a default
  6635.          string.   For example:
  6636.  
  6637.                            strcpy(str,"ABC");
  6638.  
  6639.          WindowGetString(w,2,1,str,' ',3,3,0,"3[A-Z]");
  6640.  
  6641.          The default value of "ABC" will be displayed in the window
  6642.          when WindowGetString() is called.  Therefore, make sure that
  6643.          your string buffer has a 0 in the 0th position if you want to
  6644.          make sure your input is empty when WindowGetString() is
  6645.          called.  When inputting information, hitting the Escape key
  6646.          (or whatever the current key definition is for
  6647.          window_edit_key[7]) will abort input and will return the
  6648.          original default string.
  6649.  
  6650.          The fifth argument is the fill character.  This character is
  6651.          used to fill any unfilled input positions on the window.
  6652.          Instead of having spaces for unfilled positions, you can have
  6653.          any character.  Try ASCII 177 or the underline character.
  6654.          You may like the effect.
  6655.  
  6656.          The sixth argument is the minimum number of characters to
  6657.          accept.  If the number of characters entered is less than
  6658.          minchars, the input manager will not accept the input.
  6659.          However, you can change this by allowing the input manager to
  6660.          call a user defined routine when it detects that the minimum
  6661.          number of characters was not satisfied.  More information on
  6662.          this later in this section.
  6663.  
  6664.  
  6665.  
  6666.  
  6667.          Page 97          The C Window Library               Page 97
  6668.  
  6669.          The seventh argument is the maximum width of the displayable
  6670.          input field.  This argument allows for scrollable input
  6671.          fields.  If the maximum width of the displayable field is
  6672.          less than the total number of characters in the input field,
  6673.          the field will scroll right and left depending on the input
  6674.          position.  If the input cursor exceeds the right edge of the
  6675.          displayable field, the input is scrolled right until the next
  6676.          input position is visible.  If the cursor is moved beyond the
  6677.          left edge of the displayable field, the input is scrolled
  6678.          left until the previous input position comes into view.
  6679.          Scrolling input fields allow for large input fields in small
  6680.          windows.
  6681.  
  6682.          The eighth argument is an integer representing the various
  6683.          options available for the input field.  The various options
  6684.          available will be discussed later on.
  6685.  
  6686.          The ninth argument is the starting position in the input
  6687.          string of where the cursor will be placed.  Position numbers
  6688.          start from 1 to the maximum number of input positions.  For
  6689.          most applications, the starting position is usually 1.  If
  6690.          the starting position is not within bounds of the input
  6691.          string, the starting position is assumed to be 1.
  6692.  
  6693.          The last argument is the regular expression to use for the
  6694.          input.  Make sure that the input buffer you provide is large
  6695.          enough to hold the maximum number of characters plus one more
  6696.          character for the terminating null character.
  6697.  
  6698.  
  6699.          More Examples:
  6700.  
  6701.          WindowGetString(w,2,1,str,' ',1,1,NO_OPTIONS,1,"[YyNn]");
  6702.  
  6703.          This will accept one character but only if the character is
  6704.          'Y','y','N', or 'n'.  Another example is this:
  6705.  
  6706.  
  6707.          WindowGetString(w,2,1,str,' ',5,5,NO_OPTIONS,1,"5[0-9]");
  6708.  
  6709.          This will allow the user to enter five digit characters.
  6710.  
  6711.  
  6712.          To accept all characters, use this:
  6713.          WindowGetString(w,2,1,str,' ',3,3,NO_OPTIONS,1,".");
  6714.  
  6715.  
  6716.          Example Program:
  6717.  
  6718.  
  6719.          #include "window.h"
  6720.          #include <string.h>
  6721.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  6722.  
  6723.          WPOINTER w;
  6724.  
  6725.  
  6726.  
  6727.          Page 98          The C Window Library               Page 98
  6728.  
  6729.          char buffer[80];
  6730.          main()
  6731.          {
  6732.            int i,row,col;
  6733.            buffer[0] = 0;   /* Make sure first character is null */
  6734.            WindowInitializeSystem();
  6735.            WindowSaveInitial(0);
  6736.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6737.            WindowOpen(w);
  6738.            WindowDisplay(w,1,NOEFFECT);
  6739.            buffer[0] = 0;   /* Make sure first character is NULL */
  6740.            WindowWriteString(w,"Enter Your first name :",1,1);
  6741.            WindowGetString(w,2,1,buffer,' ',0,40,NO_OPTIONS,1,"40.");
  6742.            WindowWriteString(w,"You entered the following:",3,1);
  6743.            WindowWriteString(w,buffer,4,1);
  6744.            GET_KEY();
  6745.            WindowWriteString(w,"Now Enter your last name:",6,1);
  6746.  
  6747.            /* Note that the last string is now used as a default */
  6748.            WindowGetString(w,7,1,buffer,' ',0,40,NO_OPTIONS,1,"40.");
  6749.            WindowWriteString(w,"You entered the following:",8,1);
  6750.            WindowWriteString(w,buffer,9,1);
  6751.          }
  6752.  
  6753.  
  6754.  
  6755.          If there are no errors, WindowGetString() returns NO_ERROR.
  6756.          If there are errors, WindowGetString() returns the following:
  6757.  
  6758.          BAD_WINDOW if the window does not exist.
  6759.  
  6760.          WINDOW_NOT_OPEN if the window is not open for writing (use
  6761.          WindowOpen())
  6762.  
  6763.          NO_HEAP_MEM if there is not enough memory to allocate for
  6764.          internal buffers.
  6765.  
  6766.          NO_INPUT_CHARS if the regular expression indicates no
  6767.          characters to accept.
  6768.  
  6769.  
  6770.          WindowGetStringAttr()
  6771.          ---------------------
  6772.  
  6773.          The WindowGetStringAttr() function is the same as the
  6774.          WindowGetString() function described above except that a
  6775.          video attribute is used for the input entered.  Here is the
  6776.          prototype:
  6777.  
  6778.          int WindowGetStringAttr(WPOINTER w, int row, int col,
  6779.                                  char *buffer, int fillchar,
  6780.                                  int minchars, int maxwidth,
  6781.                                  int options, int startpos, int attr,
  6782.                                  char *regexp)
  6783.  
  6784.  
  6785.  
  6786.  
  6787.          Page 99          The C Window Library               Page 99
  6788.  
  6789.          Note that attr is the tenth argument.  This is the video
  6790.          attribute to use when receiving input.
  6791.  
  6792.  
  6793.          Example Program:
  6794.  
  6795.          #include "window.h"
  6796.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6797.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  6798.  
  6799.          WPOINTER w;
  6800.          char buffer[80];
  6801.          main()
  6802.          {
  6803.            int i,row,col;
  6804.            buffer[0] = 0;   /* Make sure first character is NULL */
  6805.            WindowInitializeSystem();
  6806.            WindowSaveInitial(0);
  6807.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6808.            WindowOpen(w);
  6809.            WindowDisplay(w,1,NOEFFECT);
  6810.            buffer[0] = 0;   /* Make sure first character is null */
  6811.            WindowWriteString(w,"Enter Your first name :",1,1);
  6812.            WindowGetStringAttr(w,2,1,buffer,' ',0,40,NO_OPTIONS,1,
  6813.                                REVERSE,"40.");
  6814.            WindowWriteString(w,"You entered the following:",3,1);
  6815.            WindowWriteString(w,buffer,4,1);
  6816.            GET_KEY();
  6817.            WindowWriteString(w,"Now Enter your last name:",6,1);
  6818.  
  6819.            /* Note that the last string is now used as a default */
  6820.            WindowGetStringAttr(w,7,1,buffer,' ',0,40,NO_OPTIONS,1,
  6821.                                REVERSE,"40.");
  6822.            WindowWriteString(w,"You entered the following:",8,1);
  6823.            WindowWriteString(w,buffer,9,1);
  6824.          }
  6825.  
  6826.          The return values for WindowGetStringAttr() are the same as
  6827.          WindowGetString().
  6828.  
  6829.  
  6830.  
  6831.  
  6832.          WindowGetMaskString()
  6833.          ---------------------
  6834.  
  6835.          The WindowGetMaskString() function is the same as the
  6836.          WindowGetString() except that a character mask is used when
  6837.          editing the input.  Here is the prototype:
  6838.  
  6839.          int WindowGetMaskString(WPOINTER w, int row, int col,
  6840.                                  char *buffer, char *mask,
  6841.                                  int fillchar, int minchars,
  6842.                                  int maxwidth, int options,
  6843.                                  int startpos, char *regexp)
  6844.  
  6845.  
  6846.  
  6847.          Page 100          The C Window Library               Page 100
  6848.  
  6849.          The mask argument is an extra argument.  This is the
  6850.          character mask to use when editing the input.  The string
  6851.          returned in the buffer does not contain any characters that
  6852.          are used for the mask.  For instance, if the mask is
  6853.          "__/__/__", and the string entered is "121589",
  6854.          WindowGetMaskString() will place "121589" into the buffer.
  6855.          If you want to create a string with the components separated
  6856.          according to a mask pattern, use the
  6857.          TranslateStringToMaskString() function described later in the
  6858.          manual.  Default strings must be set up 'unmasked'.  For
  6859.          instance, if you wanted the default date to be "12/15/89",
  6860.          and the character mask is "__/__/__", your string buffer
  6861.          should contain "121589" before calling WindowGetMaskString().
  6862.          This same rule applies to any input functions that use a
  6863.          character mask.
  6864.  
  6865.          Example:
  6866.  
  6867.          #include "window.h"
  6868.          #include <string.h>
  6869.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6870.          #define TELMASK "(___)___-____ ext:____"
  6871.          #define SSMASK  "___-__-____"
  6872.  
  6873.          WPOINTER w;
  6874.          char buffer[80];
  6875.          main()
  6876.          {
  6877.            int i,row,col;
  6878.            buffer[0] = 0;   /* Make sure first character is null */
  6879.            WindowInitializeSystem();
  6880.            WindowSaveInitial(0);
  6881.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6882.            WindowOpen(w);
  6883.            WindowDisplay(w,1,NOEFFECT);
  6884.            buffer[0] = 0;   /* Make sure first character is null */
  6885.            WindowWriteString(w,"Enter Your Telephone No.",1,1);
  6886.            WindowGetMaskString(w,2,1,buffer,TELMASK,' ',0,40,
  6887.                                NO_OPTIONS,1,"40.");
  6888.            WindowWriteString(w,"You entered the following phone no:",
  6889.                              3,1);
  6890.            WindowWriteString(w,buffer,4,1);
  6891.            GET_KEY();
  6892.            memset(buffer,0,sizeof(buffer));
  6893.            WindowWriteString(w,"Now Enter your Soc. Sec. Number:",
  6894.                              6,1);
  6895.            WindowGetMaskString(w,7,1,buffer,SSMASK,' ',0,40,
  6896.                                NO_OPTIONS,1,"40.");
  6897.            WindowWriteString(w,"You entered the following:",8,1);
  6898.            WindowWriteString(w,buffer,9,1);
  6899.          }
  6900.  
  6901.          If there are no errors, WindowGetMaskString() returns
  6902.          NO_ERROR.
  6903.  
  6904.  
  6905.  
  6906.  
  6907.          Page 101          The C Window Library               Page 101
  6908.  
  6909.          If there are errors, WindowGetMaskString() returns the
  6910.          following:
  6911.  
  6912.  
  6913.          BAD_WINDOW if the window does not exist.
  6914.  
  6915.          WINDOW_NOT_OPEN if the window is not open for writing (use
  6916.          WindowOpen())
  6917.  
  6918.          NO_HEAP_MEM if there is not enough memory to allocate for
  6919.          internal buffers.
  6920.  
  6921.  
  6922.  
  6923.  
  6924.          WindowGetMaskStringAttr()
  6925.          -------------------------
  6926.  
  6927.          The WindowGetMaskStringAttr() functions works the same way as
  6928.          WindowGetMaskString() except that WindowGetMaskStringAttr()
  6929.          allows you to specify a video attribute to use for the
  6930.          characters that are entered.  Here is the prototype:
  6931.  
  6932.          int WindowGetMaskStringAttr(WPOINTER w, int row, int col,
  6933.                                      char *buffer, char *mask,
  6934.                                      int fillchar, int minchars,
  6935.                                      int maxwidth, int options,
  6936.                                      startpos, int attr, char *regexp)
  6937.  
  6938.          Example:
  6939.  
  6940.          #include "window.h"
  6941.          #include <string.h>
  6942.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  6943.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  6944.          #define TELMASK "(___)___-____ ext:____"
  6945.          #define SSMASK  "___-__-____"
  6946.          WPOINTER w;
  6947.          char buffer[80];
  6948.          main()
  6949.          {
  6950.            int i,row,col;
  6951.            buffer[0] = 0;   /* Make sure first character is null */
  6952.            WindowInitializeSystem();
  6953.            WindowSaveInitial(0);
  6954.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6955.            WindowOpen(w);
  6956.            WindowDisplay(w,1,NOEFFECT);
  6957.            buffer[0] = 0;   /* Make sure first character is null */
  6958.            WindowWriteString(w,"Enter Your Telephone No.",1,1);
  6959.            WindowGetMaskStringAttr(w,2,1,buffer,TELMASK,' ',0,40,
  6960.                                    NO_OPTIONS,1,REVERSE,"40.");
  6961.            WindowWriteString(w,"You entered the following phone no:",
  6962.                              3,1);
  6963.            WindowWriteString(w,buffer,4,1);
  6964.  
  6965.  
  6966.  
  6967.          Page 102          The C Window Library               Page 102
  6968.  
  6969.            GET_KEY();
  6970.            memset(buffer,0,sizeof(buffer));
  6971.            WindowWriteString(w,"Now Enter your Soc. Sec. Number:",6,1);
  6972.            WindowGetMaskStringAttr(w,7,1,buffer,SSMASK,' ',0,40,
  6973.                                    NO_OPTIONS,1,REVERSE,"40.");
  6974.            WindowWriteString(w,"You entered the following:",8,1);
  6975.            WindowWriteString(w,buffer,9,1);
  6976.          }
  6977.  
  6978.          The return values for WindowGetMaskStringAttr() are the same
  6979.          as WindowGetMaskString().
  6980.  
  6981.  
  6982.          Getting Passwords
  6983.          -----------------
  6984.  
  6985.          The C Window Library also allows you to receive hidden input.
  6986.          The functions to perform this are WindowGetPassword(),
  6987.          WindowGetMaskPassword(), WindowGetPasswordAttr() and
  6988.          WindowGetMaskPasswordAttr().  These functions are similar to
  6989.          the other WindowGetxx() functions. except that a character
  6990.          specified by you is displayed instead of the actual key
  6991.          pressed.
  6992.  
  6993.  
  6994.          WindowGetPassword()
  6995.          -------------------
  6996.  
  6997.          The WindowGetPassword() function gets hidden input from a
  6998.          window.  Here is the prototype:
  6999.  
  7000.          int WindowGetPassword(WPOINTER w, int row, int col,
  7001.                                char *buffer, int fillchar,
  7002.                                int passchar, int minchars,
  7003.                                int maxwidth, int options,
  7004.                                int startpos, char *regexp)
  7005.  
  7006.          The first argument is the window pointer.  The second and
  7007.          third arguments are the (row,col) to start receiving input.
  7008.          The fourth argument is the buffer to store the inputted
  7009.          characters.  The fifth argument is the character to use to
  7010.          fill empty input positions on the screen.  The sixth argument
  7011.          is the character to display to the screen when a key is
  7012.          pressed.  The last four arguments are the same as the
  7013.          WindowGetString()'s last four arguments.
  7014.  
  7015.          For example, if the user typed "ABCDEF", and the passchar is
  7016.          '*', the screen will display "******".  Notice the asterisk
  7017.          is displayed instead of the actual characters inputted.
  7018.  
  7019.  
  7020.          Example Program:
  7021.  
  7022.          #include "window.h"
  7023.          #include <string.h>
  7024.  
  7025.  
  7026.  
  7027.          Page 103          The C Window Library               Page 103
  7028.  
  7029.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  7030.  
  7031.          WPOINTER w;
  7032.          char buffer[80];
  7033.          main()
  7034.          {
  7035.            int i,row,col;
  7036.            buffer[0] = 0;   /* Make sure first character is null */
  7037.            WindowInitializeSystem();
  7038.            WindowSaveInitial(0);
  7039.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  7040.            WindowOpen(w);
  7041.            WindowDisplay(w,1,NOEFFECT);
  7042.            buffer[0] = 0;   /* Make sure first character is null */
  7043.            WindowWriteString(w,"Enter A Password",1,1);
  7044.            WindowGetPassword(w,2,1,buffer,' ','*',0,40,NO_OPTIONS,
  7045.                              1,"40.");
  7046.            WindowWriteString(w,"You entered the following:",3,1);
  7047.            WindowWriteString(w,buffer,4,1);
  7048.          }
  7049.  
  7050.          The return values for WindowGetPassword() are the same as
  7051.          WindowGetMaskString().
  7052.  
  7053.  
  7054.  
  7055.          WindowGetPasswordAttr()
  7056.          -----------------------
  7057.  
  7058.          The WindowGetPasswordAttr() function is the same as
  7059.          WindowGetPassword() except that a video attribute is
  7060.          specified for the input characters.  Here is the prototype:
  7061.  
  7062.          int WindowGetPasswordAttr(WPOINTER w, int row, int col,
  7063.                                    char *buffer, int fillchar,
  7064.                                    int passchar, int minchars,
  7065.                                    int maxwidth, int options,
  7066.                                    int startpos, int attr,
  7067.                                    char *regexp)
  7068.  
  7069.          Please note that the attribute argument is the next to last
  7070.          argument in the function.
  7071.  
  7072.  
  7073.  
  7074.          Example Program:
  7075.  
  7076.          #include "window.h"
  7077.          #include <string.h>
  7078.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  7079.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7080.  
  7081.          WPOINTER w;
  7082.          char buffer[80];
  7083.  
  7084.  
  7085.  
  7086.  
  7087.          Page 104          The C Window Library               Page 104
  7088.  
  7089.          main()
  7090.          {
  7091.            int i,row,col;
  7092.            buffer[0] = 0;   /* Make sure first character is null */
  7093.            WindowInitializeSystem();
  7094.            WindowSaveInitial(0);
  7095.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  7096.            WindowOpen(w);
  7097.            WindowDisplay(w,1,NOEFFECT);
  7098.            buffer[0] = 0;   /* Make sure first character is null */
  7099.            WindowWriteString(w,"Enter A Password",1,1);
  7100.            WindowGetPasswordAttr(w,2,1,buffer,' ','*',0,40,
  7101.                                  NO_OPTIONS,1,REVERSE,"40.");
  7102.            WindowWriteString(w,"You entered the following:",3,1);
  7103.            WindowWriteString(w,buffer,4,1);
  7104.          }
  7105.  
  7106.          The return values for WindowGetPasswordAttr() are the same as
  7107.          WindowGetMaskString().
  7108.  
  7109.  
  7110.  
  7111.          WindowGetMaskPassword()
  7112.          -----------------------
  7113.  
  7114.          The WindowGetMaskPassword() function works just like
  7115.          WindowGetPassword() except that a character mask is supplied.
  7116.          Here is the prototype:
  7117.  
  7118.          int WindowGetMaskPassword(WPOINTER w, int row, int col,
  7119.                                    char *buffer, char *mask,
  7120.                                    int fillchar, int passchar,
  7121.                                    int minchars, int maxwidth,
  7122.                                    int options, int startpos,
  7123.                                    char *regexp)
  7124.  
  7125.          Example:
  7126.  
  7127.  
  7128.          #include "window.h"
  7129.          #include <string.h>
  7130.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  7131.          #define CREDITCARDMASK "____-____-____-____"
  7132.  
  7133.          WPOINTER w;
  7134.          char buffer[80];
  7135.          main()
  7136.          {
  7137.            int i,row,col;
  7138.            buffer[0] = 0;   /* Make sure first character is null */
  7139.            WindowInitializeSystem();
  7140.            WindowSaveInitial(0);
  7141.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  7142.            WindowOpen(w);
  7143.            WindowDisplay(w,1,NOEFFECT);
  7144.  
  7145.  
  7146.  
  7147.          Page 105          The C Window Library               Page 105
  7148.  
  7149.            buffer[0] = 0;   /* Make sure first character is null */
  7150.            WindowWriteString(w,"Enter A Credit Card #",1,1);
  7151.            WindowGetMaskPassword(w,2,1,buffer,CREDITCARDMASK,' ','*',
  7152.                                  0,40,NO_OPTIONS,1,"40.");
  7153.            WindowWriteString(w,"You entered the following:",3,1);
  7154.            WindowWriteString(w,buffer,4,1);
  7155.          }
  7156.  
  7157.  
  7158.          The return values for WindowGetMaskPassword() are the same as
  7159.          WindowGetMaskString().
  7160.  
  7161.  
  7162.  
  7163.  
  7164.          WindowGetMaskPasswordAttr()
  7165.          ---------------------------
  7166.  
  7167.          The WindowGetMaskPasswordAttr() function works just like
  7168.          WindowGetMaskPassword() except that a video attribute is
  7169.          supplied. Here is the prototype:
  7170.  
  7171.  
  7172.          int WindowGetMaskPasswordAttr(WPOINTER w, int row, int col,
  7173.                                        char *buffer, char *mask,
  7174.                                        int fillchar, int passchar,
  7175.                                        int minchars, int maxwidth,
  7176.                                        int options, int startpos,
  7177.                                        int attr, char *regexp)
  7178.  
  7179.          Example:
  7180.  
  7181.  
  7182.          #include "window.h"
  7183.          #include <string.h>
  7184.          #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  7185.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7186.          #define CREDITCARDMASK "____-____-____-____"
  7187.  
  7188.          WPOINTER w;
  7189.          char buffer[80];
  7190.          main()
  7191.          {
  7192.            int i,row,col;
  7193.            buffer[0] = 0;   /* Make sure first character is null */
  7194.            WindowInitializeSystem();
  7195.            WindowSaveInitial(0);
  7196.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  7197.            WindowOpen(w);
  7198.            WindowDisplay(w,1,NOEFFECT);
  7199.            buffer[0] = 0;   /* Make sure first character is null */
  7200.            WindowWriteString(w,"Enter A Credit Card #",1,1);
  7201.            WindowGetMaskPasswordAttr(w,2,1,buffer,CREDITCARDMASK,' ',
  7202.                                      '*',0,40, NO_OPTIONS,1,REVERSE,
  7203.                                      "40.");
  7204.  
  7205.  
  7206.  
  7207.          Page 106          The C Window Library               Page 106
  7208.  
  7209.  
  7210.            WindowWriteString(w,"You entered the following:",3,1);
  7211.            WindowWriteString(w,buffer,4,1);
  7212.          }
  7213.  
  7214.  
  7215.          The return values for WindowGetMaskPasswordAttr() are the
  7216.          same as WindowGetMaskString().
  7217.  
  7218.  
  7219.  
  7220.  
  7221.          Undefined Keystroke Processing
  7222.          ------------------------------
  7223.  
  7224.          Another powerful feature of the input functions is that you
  7225.          can call a function for keys that are not in the current key
  7226.          definitions.  For instance, say you want the Enter key AND
  7227.          Control-R to mean accept the input.  Since there is only room
  7228.          for one definition for accept input, you can write a function
  7229.          that checks for the Control-R key, and return a number to the
  7230.          input manager as to what action to take.
  7231.  
  7232.          The undef_fkey_func and undef_akey_func function pointers
  7233.          ---------------------------------------------------------
  7234.  
  7235.          There are two global variables, undef_fkey_func and
  7236.          undef_akey_func.  Both of these function pointers are defined
  7237.          in the file key.h.  These two variables are pointers to
  7238.          functions that return an integer.  By setting these functions
  7239.          to point to your own functions, you can process undefined
  7240.          keystrokes yourself and return to the input manager what
  7241.          action to take.
  7242.  
  7243.          The undef_fkey_func is used to define keys that are not
  7244.          normal ASCII keys.  For instance, Control key and Alt key
  7245.          combinations, the F-keys, PgDn and PgUp, etc.  The
  7246.          undef_akey_func is used to define normal ASCII keys (keys
  7247.          with ASCII values between 32 and 255, inclusive).
  7248.  
  7249.          Whenever an undefined key is encountered, the input manager
  7250.          will pass the string that has been currently entered, the
  7251.          current key pressed, the current position number of the
  7252.          character being processed, and a pointer to a new position to
  7253.          place the input cursor.  The prototype for this function is
  7254.          as follows:
  7255.  
  7256.           int (*undef_fkey_func)(char *str,int key,
  7257.                                  int pos,int *newposptr)
  7258.  
  7259.          The prototype to the undef_akey_func is similar to the one
  7260.          above.
  7261.  
  7262.          The str is a pointer to a null-terminated string of
  7263.          characters that has been currently entered.  For instance, if
  7264.  
  7265.  
  7266.  
  7267.          Page 107          The C Window Library               Page 107
  7268.  
  7269.          the string currently entered is
  7270.  
  7271.                      ABC123
  7272.  
  7273.          str will point to "ABC123".
  7274.  
  7275.          The second argument is the last key that was pressed.  You
  7276.          should use the values defined in the header file "keycodes.h"
  7277.          if you want to check for non-ascii keys.  This will ensure
  7278.          that you are properly checking the keystroke desired.  For
  7279.          instance, if you want to check if the key pressed was the
  7280.          Page Up key, use the constant PGUP defined in keycodes.h.
  7281.  
  7282.          The third argument is an integer representing the position
  7283.          number of the current character that the cursor is on.  The
  7284.          first character is at position number 0, the second character
  7285.          in the input field is 1, etc.  If there is an input mask (as
  7286.          in WindowGetMaskString() and WindowGetMaskStringAttr()) the
  7287.          position number does not include any characters that are used
  7288.          to create the non-input positions.  For instance:
  7289.  
  7290.                              "__/__/__ "
  7291.                               01 23 45
  7292.  
  7293.          The numbers under the mask are the position numbers for each
  7294.          character.
  7295.  
  7296.          The fourth argument is a pointer to an integer representing a
  7297.          new position to move the cursor.  Use of this pointer will be
  7298.          explained later.  for this argument will be made evident
  7299.          later.  The reason for the third argument being a pointer
  7300.          rather than an integer will be evident later on.
  7301.  
  7302.  
  7303.  
  7304.          Specifying when to call an undefined key function in a
  7305.          Regular Expression
  7306.          -------------------------------
  7307.  
  7308.          An empty bracketed simple regular expression tells the input
  7309.          manager to call the undefined keystroke function.  An example
  7310.          of this type of regular expression is as follows:
  7311.  
  7312.                  Regular                  Definition
  7313.                Expression                 ----------
  7314.                ----------
  7315.  
  7316.                 [A-Z][]                  The first input position must
  7317.                                          be btween 'A' and 'Z', and
  7318.                                          the second position will
  7319.                                          automatically call the user
  7320.                                          defined undefined keystroke
  7321.                                          function.
  7322.  
  7323.                 20[]                     All twenty input positions
  7324.  
  7325.  
  7326.  
  7327.          Page 108          The C Window Library               Page 108
  7328.  
  7329.                                          will call the undefined
  7330.                                          keystroke function.
  7331.  
  7332.                 3[0-9]2[]2[A-Z]          The first three input
  7333.                                          positions must be between '0'
  7334.                                          and '9', the next two input
  7335.                                          positions automatically call
  7336.                                          the undefined keystroke
  7337.                                          function, and the last two
  7338.                                          positions must be between 'A'
  7339.                                          and 'Z'.
  7340.  
  7341.  
  7342.  
  7343.          If you use this form of a regular expression, you MUST have
  7344.          defined an undefined keystroke function.  If you did not
  7345.          define one, you will more than likely get into an infinite
  7346.          loop.  Using this form of regular expression combined with
  7347.          the return values (defined below) that can be returned to the
  7348.          input manager, you will virtually have total control of the
  7349.          way the input is handled.
  7350.  
  7351.  
  7352.          Return Values To The Input Manager
  7353.          ----------------------------------
  7354.  
  7355.          When writing your function you must return an integer to the
  7356.          input manager.  This integer will inform the input manager as
  7357.          to what action to take.  Here are a list of the return values
  7358.          and what they inform the input manager:
  7359.  
  7360.  
  7361.  
  7362.            Return                         Action to
  7363.            Value                            Take
  7364.            ------                         ---------
  7365.  
  7366.            DONT_PROCESS           Do not Process keystroke and
  7367.                                   continue getting input.
  7368.  
  7369.            MOVE_CURSOR_LEFT       Move cursor left.
  7370.  
  7371.            MOVE_CURSOR_RIGHT      Move cursor right.
  7372.  
  7373.            DELETE_AT_CURSOR       Delete character at cursor.
  7374.  
  7375.            TOGGLE_INSERT          Toggle Insert/Overwrite mode.
  7376.  
  7377.            DESTRUCT_BACKSPACE     Destructive Backspace.
  7378.  
  7379.            ACCEPT_INPUT           Accept Input and return string.
  7380.  
  7381.            ACCEPT_DEFAULT         Accept default string and return.
  7382.  
  7383.            ERASE_INPUT            Erase Input and go to first
  7384.  
  7385.  
  7386.  
  7387.          Page 109          The C Window Library               Page 109
  7388.  
  7389.                                   character in input field.
  7390.  
  7391.            GOTO_FIRST             Go to first input character in
  7392.                                   field.
  7393.  
  7394.            GOTO_LAST              Move cursor to last input character
  7395.                                   in field.
  7396.  
  7397.            MOVE_TO_CHARACTER      Move cursor to input position
  7398.                                   specified in the *pos argument.
  7399.  
  7400.            INSERT_CHARACTER       Accept character as valid and insert
  7401.                                   it at the current cursor position.
  7402.  
  7403.  
  7404.  
  7405.          The MOVE_TO_CHARACTER return value moves the input cursor to
  7406.          the position in the input string specified in the fourth
  7407.          argument of undef_akey_func or undef_fkey_func.  If you
  7408.          recall, the fourth argument was a pointer to an integer.
  7409.  
  7410.          The INSERT_CHARACTER return value only applies to the
  7411.          function pointed to by undef_akey_func.
  7412.  
  7413.          These user-defined functions can do anything, not just
  7414.          process keystrokes.  For instance, if you want F1 to be a
  7415.          help key, where the help function is in a function called
  7416.          do_help() you must make sure that:
  7417.  
  7418.          a) the F1 key is undefined (not defined in the
  7419.          window_edit_key array) b) the undef_fkey_func function
  7420.          pointer points to your function c) return an integer to the
  7421.          input manager from your function.
  7422.  
  7423.          Here is a typical way that this would be set up:
  7424.  
  7425.  
  7426.  
  7427.          #include "window.h"
  7428.  
  7429.          /*  ... Other #includes and #defines */
  7430.  
  7431.          int do_help();           /* define help function */
  7432.  
  7433.          main()
  7434.          {
  7435.            WindowInitializeSystem();
  7436.  
  7437.  
  7438.            /* ...Some code */
  7439.            undef_fkey_func = do_help;
  7440.            WindowGetString(/*  ... Parameters */);
  7441.  
  7442.            /* ... Other code */
  7443.          }
  7444.  
  7445.  
  7446.  
  7447.          Page 110          The C Window Library               Page 110
  7448.  
  7449.          int do_help(char *str, int ch, int pos, int *newpos)
  7450.          {
  7451.            if (ch == F1)                     /* check for F1 */
  7452.            {
  7453.               /* help function goes here */
  7454.              return DONT_PROCESS;  /* make sure input manager does not
  7455.                                       process this or any other
  7456.                                       undefined keystroke */
  7457.  
  7458.            }
  7459.            else
  7460.            {
  7461.              *newpos = 3;       /* move input cursor to the third
  7462.                                    input position */
  7463.  
  7464.              return MOVE_TO_CHARACTER   /* let input manager know we
  7465.                                            want to move the input
  7466.                                            cursor */
  7467.            }
  7468.          }
  7469.  
  7470.  
  7471.          With this flexibility in the input functions, you can totally
  7472.          control how input is handled.
  7473.  
  7474.  
  7475.  
  7476.  
  7477.  
  7478.  
  7479.  
  7480.  
  7481.  
  7482.  
  7483.  
  7484.  
  7485.  
  7486.  
  7487.  
  7488.  
  7489.  
  7490.  
  7491.  
  7492.  
  7493.  
  7494.  
  7495.  
  7496.  
  7497.  
  7498.  
  7499.  
  7500.  
  7501.  
  7502.  
  7503.  
  7504.  
  7505.  
  7506.  
  7507.          Page 111          The C Window Library               Page 111
  7508.  
  7509.          Input Options
  7510.          -------------
  7511.  
  7512.          In the previous examples, the available options were
  7513.          discussed briefly.  These options provide further control of
  7514.          the input functions.  Here is a list of the options that are
  7515.          available:
  7516.  
  7517.                  Option                   Definition
  7518.                  ------                   ----------
  7519.                  UPPERCASE             Translates and displays lower
  7520.                                        case to upper case.
  7521.  
  7522.                  LOWERCASE             Translates and displays upper
  7523.                                        case to lower case.
  7524.  
  7525.                  CHECKSPACES           Spaces are counted when
  7526.                                        determining whether the minimum
  7527.                                        number of characters are
  7528.                                        entered.
  7529.  
  7530.                  ENHANCEDKEY           Use the enhanced keyboard keys
  7531.                                        and distinguish between keypad
  7532.                                        keys and separate cursor pad
  7533.                                        keys.  Also detect F11 and F12
  7534.                                        keys.
  7535.  
  7536.                  CHECKREGEXP           Check to see if all characters
  7537.                                        entered agree with the regular
  7538.                                        expression provided.
  7539.  
  7540.                  AUTORETURN            Automatically accept the input
  7541.                                        when a character in the last
  7542.                                        input position is entered.
  7543.  
  7544.                  HOMECURSOR            Move scrolled input back to the
  7545.                                        first character in the input
  7546.                                        string when input is accepted.
  7547.  
  7548.                  CLEARFIELD            Clears the input field if the
  7549.                                        first key pressed is recognized
  7550.                                        by the regular expression as a
  7551.                                        valid input key.  If a cursor
  7552.                                        movement key is pressed first,
  7553.                                        the field is not cleared if any
  7554.                                        subsequent input keys are
  7555.                                        pressed.
  7556.  
  7557.                  USEMOUSE              Utilize the mouse to move the
  7558.                                        cursor in the input field.
  7559.  
  7560.                  NO_OPTIONS            No options desired.
  7561.  
  7562.  
  7563.  
  7564.  
  7565.  
  7566.  
  7567.          Page 112          The C Window Library               Page 112
  7568.  
  7569.  
  7570.          UPPERCASE
  7571.          ---------
  7572.          The UPPERCASE option converts and displays all lower case
  7573.          letters to upper case while the user is inputting characters.
  7574.  
  7575.  
  7576.          LOWERCASE
  7577.          ---------
  7578.          The LOWERCASE option converts and displays all upper case
  7579.          letters to lower case while the user is inputting characters.
  7580.  
  7581.  
  7582.          CHECKSPACES
  7583.          -----------
  7584.          The CHECKSPACES option will cause the input manager to count
  7585.          any embedded spaces when determining whether the minimum
  7586.          number of characters are reached.  Trailing spaces are
  7587.          counted only if the user explicitly put them there.
  7588.  
  7589.  
  7590.  
  7591.          ENHANCEDKEY
  7592.          -----------
  7593.          The ENHANCEDKEY option will distinguish between the cursor
  7594.          keys on the keypad from the dedicated cursor keys on the
  7595.          enhanced keyboards as well as the Ins, Home, Del, PgUp and
  7596.          PgDn keys.  Also the F11 and F12 keys will be detected.
  7597.  
  7598.  
  7599.  
  7600.          CHECKREGEXP and the reg_exp_error_func function pointer
  7601.          -------------------------------------------------------
  7602.  
  7603.          The CHECKREGEXP option will check to make sure that every
  7604.          character inputted is a valid character according to the
  7605.          regular expression.  When inserting or deleting characters
  7606.          during input, characters may be moved left or right depending
  7607.          on whether the input is in insert or overwrite mode.  When
  7608.          the characters are moved, the resulting pattern of characters
  7609.          may not match the regular expression desired.  For instance,
  7610.          if the regular expression is "3[A-Z]2[0-9]", meaning 3
  7611.          characters between A and Z followed by 2 characters between 0
  7612.          and 9, and the current input entered is as follows :
  7613.  
  7614.                         ABC34
  7615.  
  7616.          If the cursor is currently under the 'C', the delete key is
  7617.          pressed, and the input is currently in insert mode, the '34'
  7618.          will be moved one character to the left.  The resulting input
  7619.          would then look like this:
  7620.  
  7621.                         AB34
  7622.  
  7623.          As you can see, the input does not match the regular
  7624.  
  7625.  
  7626.  
  7627.          Page 113          The C Window Library               Page 113
  7628.  
  7629.          expression "3[A-Z]2[0-9]" because the '3' is in a position
  7630.          that should be occupied by a letter.  When the CHECKREGEXP
  7631.          option is chosen, each position is checked when the user
  7632.          wants to accept the string, not while the user is entering
  7633.          characters.  If the input is not OK, the input manager will
  7634.          not accept the string. You can override this by setting the
  7635.          reg_exp_error_func function pointer.
  7636.  
  7637.  
  7638.          The global function pointer reg_exp_error_func is prototyped
  7639.          as follows:
  7640.  
  7641.             int (*reg_exp_error_func)(char *buf, int nomatch);
  7642.  
  7643.          where buf is the current string entered, and nomatch is the
  7644.          position of the first non-matching character that did not
  7645.          match the regular expression.  The first character of the
  7646.          string is at position 0.
  7647.  
  7648.          Your function must return an integer back as to what to do.
  7649.          There are two valid return values, namely ACCEPT_INPUT and
  7650.          DONT_PROCESS.  A return value of ACCEPT_INPUT will accept the
  7651.          input, even though all of the characters do not match the
  7652.          regular expression.  DONT_PROCESS tells the input manager to
  7653.          keep getting input.  Here is an example:
  7654.  
  7655.  
  7656.            int my_check_func();
  7657.            main()
  7658.            {
  7659.                ...
  7660.               reg_exp_error_func = my_check_func;
  7661.  
  7662.               WindowGetString(other parameters, CHECKREGEXP,
  7663.                               "[A-Z][0-9]");
  7664.  
  7665.                ...
  7666.            }
  7667.  
  7668.            int my_check_func(char *buf, int mistake_pos)
  7669.            {
  7670.              /* Assume w is initialized and open for writing */
  7671.  
  7672.              WindowPrintf(w,
  7673.          "Illegal input for %s.  Illegal character at position %d",buf,
  7674.                           mistake_pos);
  7675.              GET_KEY();
  7676.              WindowHide(w,NOEFFECT);
  7677.              return DONT_PROCESS;
  7678.            }
  7679.  
  7680.  
  7681.          The above example shows a function called my_check_func()
  7682.          which will be called when the input manager detects that all
  7683.          of the characters in the buffer buf do not match the regular
  7684.  
  7685.  
  7686.  
  7687.          Page 114          The C Window Library               Page 114
  7688.  
  7689.          expression.  The function displays a message in a window and
  7690.          waits for a key to be pressed.  Then the function returns
  7691.          DONT_PROCESS back to the input manager.
  7692.  
  7693.  
  7694.  
  7695.          AUTORETURN
  7696.          ----------
  7697.  
  7698.          The AUTORETURN will automatically accept the input and return
  7699.          to the calling function if the cursor is on the last input
  7700.          position and the user types a valid character.  Of course, if
  7701.          CHECKREGEXP is on, the input is checked for validity.
  7702.  
  7703.  
  7704.          HOMECURSOR
  7705.          ----------
  7706.  
  7707.          The HOMECURSOR options will scroll an input field back to the
  7708.          first position when the input is accepted.
  7709.  
  7710.  
  7711.          CLEARFIELD
  7712.          ----------
  7713.  
  7714.          The CLEARFIELD option will automatically clear the input
  7715.          field of any characters if the first key struck is a key
  7716.          recognized as a valid input key, and the character is
  7717.          displayed in the input position.  If the first key struck is
  7718.          a cursor movement key or a delete character key (destructive
  7719.          backspace or delete character), any valid input key that is
  7720.          subsequently struck does not clear the field,  but is
  7721.          recorded in the input field.
  7722.  
  7723.  
  7724.          USEMOUSE
  7725.          --------
  7726.  
  7727.          This option can only be used if you have access to The C
  7728.          Window Library MouseLib functions, the system has a mouse
  7729.          installed, and the mouse has been activated.  By positioning
  7730.          the mouse cursor to any valid input position in the input
  7731.          field and pressing the mouse button defined in the global
  7732.          integer variable field_button_press, the cursor is
  7733.          automatically moved to that input position.  If the
  7734.          CLEARFIELD option is used in conjunction to USEMOUSE, any
  7735.          subsequent input will not clear the field if the mouse was
  7736.          used to move the cursor.
  7737.  
  7738.  
  7739.          NO_OPTIONS
  7740.          ----------
  7741.  
  7742.          No field options desired.  In other words, all of the options
  7743.          defined above are turned off.
  7744.  
  7745.  
  7746.  
  7747.          Page 115          The C Window Library               Page 115
  7748.  
  7749.  
  7750.  
  7751.  
  7752.          Examples of Input Options
  7753.          -------------------------
  7754.  
  7755.          Examples:
  7756.  
  7757.            a) WindowGetString(w,1,1,str,' ',1,1,UPPERCASE,"[YyNn]");
  7758.  
  7759.            b) WindowGetString(w,1,1,str,' ',1,1,LOWERCASE,"[YyNn]");
  7760.  
  7761.            c) WindowGetStringAttr(w,2,1,str,' ',
  7762.                               CREATE_VIDEO_ATTRIBUTE(black,white),1,
  7763.                               1,UPPERCASE | AUTORETURN,"[YyNn]");
  7764.  
  7765.            d) WindowGetString(w,1,1,str,' ',10,10,
  7766.                               UPPERCASE | ENHANCEDKEY,"10.");
  7767.  
  7768.            e) WindowGetString(w,1,1,str,' ',20,10,CHECKREGEXP |
  7769.                               HOMECURSOR,"10[A-Z]10[0-9]");
  7770.  
  7771.          Example a) gets one character and will automatically set this
  7772.                     character to upper case.
  7773.  
  7774.                  b) same as a) except character is converted to lower
  7775.                     case.
  7776.  
  7777.                  c) converts one character to uppercase and
  7778.                     automatically accepts the input because the input
  7779.                     cursor was on the last input position.  Note the
  7780.                     use of the bitwise OR (|) to set multiple options.
  7781.  
  7782.                  d) Converts the input to uppercase and treats extra
  7783.                     keys on an enhanced keyboard as different than
  7784.                     their "normal" keys.
  7785.  
  7786.                  e) On accepting of the input field, the input is
  7787.                     checked to see if every position on the input
  7788.                     field is checked to see if it matches the regular
  7789.                     expression.  Once the input is accepted, the input
  7790.                     is scrolled back to the first input position.
  7791.  
  7792.  
  7793.          THE num_chars_entered_func FUNCTION POINTER
  7794.          -------------------------------------------
  7795.  
  7796.          If the number of characters entered is not enough to satisfy
  7797.          the minimum number of characters allowed, by default the
  7798.          input manager will not return until the required number of
  7799.          characters is entered.  However, a global function pointer
  7800.          can be assigned to a user-written function that will be
  7801.          called when the input manager detects that the minimum number
  7802.          of characters was not reached.  The function pointer
  7803.          num_chars_entered_func is prototyped as follows:
  7804.  
  7805.  
  7806.  
  7807.          Page 116          The C Window Library               Page 116
  7808.  
  7809.  
  7810.          int (*num_chars_entered_func)(char *buf, int minchars);
  7811.  
  7812.          where buf is the current string that is entered, and minchars
  7813.          is the minimum number of characters to expect.
  7814.  
  7815.          Your function must return an integer back as to what to do.
  7816.          There are two valid return values, namely ACCEPT_INPUT and
  7817.          DONT_PROCESS.  A return value of ACCEPT_INPUT will accept the
  7818.          input, even though the minimum number of characters was not
  7819.          reached.  DONT_PROCESS tells the input manager to keep
  7820.          getting input.  Here is an example:
  7821.  
  7822.  
  7823.            int my_min_func();
  7824.            main()
  7825.            {
  7826.                ...
  7827.               num_chars_entered_func = my_min_func;
  7828.                ...
  7829.            }
  7830.  
  7831.            int my_min_func(char *buf, int m)
  7832.            {
  7833.  
  7834.              /* Assume w is initialized and open for writing */
  7835.  
  7836.              WindowWriteString(w,"Not enough characters!",1,1);
  7837.              GET_KEY();
  7838.              WindowHide(w,NOEFFECT);
  7839.              return DONT_PROCESS;
  7840.            }
  7841.  
  7842.          The above example shows a function called my_min_func() which
  7843.          will be called when the input manager detects that the number
  7844.          of characters in the buffer buf, does not meet the minimum
  7845.          requirements.  The function displays a message in a window
  7846.          and waits for a key to be pressed.  Then the function returns
  7847.          DONT_PROCESS back to the input manager.
  7848.  
  7849.  
  7850.  
  7851.  
  7852.          Other Input Related Functions
  7853.          -----------------------------
  7854.  
  7855.          There are other input related functions that you can use to
  7856.          translate strings into their character mask equivalents and
  7857.          vice-versa.
  7858.  
  7859.  
  7860.          TranslateStringToMaskString()
  7861.          -----------------------------
  7862.  
  7863.          This TranslateStringToMaskString() function takes a string
  7864.  
  7865.  
  7866.  
  7867.          Page 117          The C Window Library               Page 117
  7868.  
  7869.          and either places spaces, or the actual mask character
  7870.          between the characters in the string.  A pointer to the
  7871.          translated string is returned.  Here is the prototype:
  7872.  
  7873.  
  7874.          char *TranslateStringToMaskString(char *buffer, char *mask,
  7875.                                            char *buf2, int maskchar,
  7876.                                            int flag)
  7877.  
  7878.          The first argument is a pointer to the string to translate.
  7879.          The second argument is the mask string to use. The third
  7880.          argument is a pointer to the buffer that will store the
  7881.          translated string.  The fourth argument is the mask character
  7882.          that is to be used.  This character determines where the
  7883.          input positions are.  The flag argument tells whether to
  7884.          include spaces between each component, or to use the
  7885.          character in the mask.
  7886.  
  7887.          You must make sure that buf2 is big enough to hold the
  7888.          translated string.
  7889.  
  7890.          The string length of the mask determines how far to translate
  7891.          the string.  If the mask string is shorter than the string to
  7892.          translate, the string is truncated up to the last character
  7893.          in the mask.  If the string to translate runs out of
  7894.          characters before the mask has been totally scanned, the
  7895.          extra characters in buf2 will either be spaces, or the
  7896.          characters in the mask (not the mask character specified in
  7897.          argument 4) will be copied over.
  7898.  
  7899.          Example:
  7900.  
  7901.              #include "window.h"
  7902.  
  7903.              #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  7904.              #define DATEMASK "__/__/__"
  7905.              char buf1[] = "123456";
  7906.              char buf2[9];
  7907.              WPOINTER w;
  7908.  
  7909.              main()
  7910.              {
  7911.                WindowInitializeSystem();
  7912.                WindowSaveInitial(0);
  7913.                w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,
  7914.                                     SINGLEBOX);
  7915.                WindowOpen(w);
  7916.                WindowDisplay(w,1,NOEFFECT);
  7917.                TranslateStringToMaskString(buf1,DATEMASK,buf2,'_',0);
  7918.                WindowPrintf(w,
  7919.            "The original string is %s\nThe translated string is %s\n",
  7920.                             buf1,buf2);
  7921.                TranslateStringToMaskString(buf1,DATEMASK,buf2,'_',1);
  7922.                WindowPrintf(w,
  7923.            "The original string is %s\nThe translated string is %s\n",
  7924.                             buf1,buf2);
  7925.          }
  7926.  
  7927.          Page 118          The C Window Library               Page 118
  7928.  
  7929.  
  7930.          The example above takes the string "123456" with the mask of
  7931.          "__/__/__".  The results of a translate with a flag of 0, and
  7932.          with a flag value of 1, is displayed in window w.
  7933.  
  7934.          The return value for TranslateStringToMaskString() is the
  7935.          pointer to the buffer that holds the translated string.  This
  7936.          string is automatically null terminated.
  7937.  
  7938.  
  7939.          TranslateMaskStringToString()
  7940.          -----------------------------
  7941.  
  7942.          This TranslateMaskStringToString() function does the opposite
  7943.          of TranslateStringToMaskString().  This function takes a
  7944.          string that has been translated with the
  7945.          TranslateStringToMaskString() or contains mask characters and
  7946.          returns the string without the extra characters.  Here is the
  7947.          prototype:
  7948.  
  7949.          char *TranslateMaskStringToString(char *buffer, char *mask,
  7950.                                            char *buf2, int maskchar)
  7951.  
  7952.          The first argument is a pointer to the translated string.
  7953.          The second argument is the mask string to use. The third
  7954.          argument is a pointer to the buffer that will store the
  7955.          resulting string.  The fourth argument is the mask character
  7956.          that is to be used.  This character determines where the
  7957.          input positions are.
  7958.  
  7959.  
  7960.          You must make sure that buf2 is big enough to hold the new
  7961.          string.
  7962.  
  7963.          The translation stops when either the end of the buffer is
  7964.          reached, or the end of the mask string is reached.
  7965.  
  7966.  
  7967.          Example:
  7968.  
  7969.          #include "window.h"
  7970.          #include <string.h>
  7971.  
  7972.          #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  7973.          #define DATEMASK "__/__/__"
  7974.          char buf1[] = "12/34/56";
  7975.          char buf2[9];
  7976.          WPOINTER w;
  7977.  
  7978.          main()
  7979.          {
  7980.            memset(buf2,0,sizeof(buf2));
  7981.            WindowInitializeSystem();
  7982.  
  7983.  
  7984.  
  7985.  
  7986.  
  7987.          Page 119          The C Window Library               Page 119
  7988.  
  7989.            WindowSaveInitial(0);
  7990.            w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  7991.            WindowOpen(w);
  7992.            WindowDisplay(w,1,NOEFFECT);
  7993.            TranslateMaskStringToString(buf1,DATEMASK,buf2,'_');
  7994.            WindowPrintf(w,"The original string is %s\n"
  7995.                          "The untranslated string is %s\n", buf1,buf2);
  7996.          }
  7997.  
  7998.  
  7999.          The example above takes the string "12/34/56" with the mask
  8000.          of "__/__/__".  The results of the translation is displayed
  8001.          in window w.
  8002.  
  8003.          The return value for TranslateMaskStringToString() is the
  8004.          pointer to the buffer that holds the translated string.  This
  8005.          string is automatically null terminated.
  8006.  
  8007.  
  8008.  
  8009.  
  8010.  
  8011.  
  8012.  
  8013.  
  8014.  
  8015.  
  8016.  
  8017.  
  8018.  
  8019.  
  8020.  
  8021.  
  8022.  
  8023.  
  8024.  
  8025.  
  8026.  
  8027.  
  8028.  
  8029.  
  8030.  
  8031.  
  8032.  
  8033.  
  8034.  
  8035.  
  8036.  
  8037.  
  8038.  
  8039.  
  8040.  
  8041.  
  8042.  
  8043.  
  8044.  
  8045.  
  8046.  
  8047.          Page 120          The C Window Library               Page 120
  8048.  
  8049.                            VIRTUAL WINDOWS
  8050.                            ---------------
  8051.  
  8052.          A virtual window can be thought of as a rectangular area
  8053.          filled with text.  This rectangular region can be broken up
  8054.          into rows and columns, just as a normal window can be divided
  8055.          into rows and columns.  The differences between a virtual
  8056.          window and a regular window is that a virtual window's
  8057.          dimensions can be larger than the physical screen, and a
  8058.          virtual window is not displayed on the screen.  Then what
  8059.          good is it if you cannot display it?  You use regular windows
  8060.          to display portions of the virtual window.  If a regular
  8061.          window is used to view a virtual window, the regular window
  8062.          is called a viewport.  With this method, you can use a
  8063.          viewport to display a virtual window, and then 'pan' around,
  8064.          viewing different sections of the virtual window.  Text
  8065.          editors use this method to display files.  Scrolling popup
  8066.          menus also use virtual windows.
  8067.  
  8068.          With The C Window Library, you can create virtual windows of
  8069.          any size, up to available user memory.  You can have a
  8070.          maximum of 256 virtual windows defined at the same time.
  8071.  
  8072.  
  8073.  
  8074.          Using Windows as Viewports
  8075.          --------------------------
  8076.  
  8077.          If text is written to a virtual window, and there is a
  8078.          viewport that is displaying the portion of the virtual window
  8079.          that has changed, the viewport will show the change
  8080.          immediately.  You do not have to "repaint" or "refresh" the
  8081.          viewport to show an updated change.  That is handled
  8082.          internally in The C Window Library.  However, there is an
  8083.          option that will "freeze" a viewport, i.e. will not update
  8084.          automatically, if there is a change in the virtual window.
  8085.          When the viewport is unfrozen, the changes to the virtual
  8086.          window are than displayed.
  8087.  
  8088.  
  8089.  
  8090.  
  8091.          Attributed and Non-Attributed Virtual Windows
  8092.          ---------------------------------------------
  8093.  
  8094.          There are two types of virtual windows.  You can have either
  8095.          a virtual window with its own video attributes or a virtual
  8096.          window which gets its video attributes from the viewport that
  8097.          is displaying the virtual window.  Virtual windows without
  8098.          attributes use half as much memory as a virtual window with
  8099.          attributes, but attributed virtual window's are more
  8100.          flexible.  For instance, lets say you have highlighted some
  8101.          text in the virtual window.  If the virtual window is not
  8102.          attributed, you must write the highlight attribute to the
  8103.          viewport window using one of the window functions
  8104.  
  8105.  
  8106.  
  8107.          Page 121          The C Window Library               Page 121
  8108.  
  8109.          (WindowWriteStringAttr() for example), since the virtual
  8110.          window does not have the capacity to store the video
  8111.          attribute.  If you were to scroll the highlighted portion out
  8112.          of the viewport, you lose the highlight attribute, and must
  8113.          call the window function again to highlight the text, if the
  8114.          text is displayed again in the viewport.  With an attributed
  8115.          virtual window, you write the attributes to the virtual
  8116.          window.  Since the attributes are stored in the virtual
  8117.          window structure itself, the attributes are retained until
  8118.          you change them.
  8119.  
  8120.          From this point on, virtual windows without attributes are
  8121.          called NOATTRIBUTE virtual windows.  Virtual windows with
  8122.          attributes will be called ATTRIBUTE virtual windows.
  8123.  
  8124.  
  8125.          Virtual Window's Logical Cursor
  8126.          -------------------------------
  8127.  
  8128.          Each virtual window has its own logical cursor.  This cursor
  8129.          is updated automatically when calling VirtualPrintf(), and
  8130.          VirtualWriteCharacter() functions, or can be updated manually
  8131.          by calling the VirtualMoveCursor() function.  This cursor is
  8132.          independent of the screen cursor.
  8133.  
  8134.  
  8135.  
  8136.  
  8137.  
  8138.  
  8139.  
  8140.  
  8141.  
  8142.  
  8143.  
  8144.  
  8145.  
  8146.  
  8147.  
  8148.  
  8149.  
  8150.  
  8151.  
  8152.  
  8153.  
  8154.  
  8155.  
  8156.  
  8157.  
  8158.  
  8159.  
  8160.  
  8161.  
  8162.  
  8163.  
  8164.  
  8165.  
  8166.  
  8167.          Page 122          The C Window Library               Page 122
  8168.  
  8169.                       CREATING VIRTUAL WINDOWS
  8170.                       ------------------------
  8171.  
  8172.          The section will discuss creating virtual windows using the
  8173.          VirtualInitialize() function.
  8174.  
  8175.  
  8176.          VirtualInitialize()
  8177.          -------------------
  8178.  
  8179.          Virtual windows are created by calling the
  8180.          VirtualInitialize() function.  Here is the prototype:
  8181.  
  8182.          VWPOINTER VirtualInitialize(int vwtype, unsigned nrows,
  8183.                                      unsigned ncols, int attr)
  8184.  
  8185.          The VirtualInitialize() function returns a pointer to a
  8186.          virtual window structure (a VWPOINTER).  The first argument
  8187.          to VirtualInitialize() tells whether the virtual window will
  8188.          or will not have its own video attributes.  If this argument
  8189.          is NOATTRIBUTE, the virtual window will not have attributes,
  8190.          otherwise if it is ATTRIBUTE, the virtual window will have
  8191.          its own attributes.  The second argument is the number of
  8192.          rows of the virtual window.  The third argument is the number
  8193.          of columns.  The fourth argument is the attribute to use for
  8194.          the virtual window.  This argument is ignored if the virtual
  8195.          window is NOATTRIBUTE.
  8196.  
  8197.          Example:
  8198.  
  8199.          #include "window.h"
  8200.          #include <stdio.h>
  8201.  
  8202.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8203.          VWPOINTER vw1,          /* virtual window pointers */
  8204.                    vw2;
  8205.          main()
  8206.          {
  8207.            WindowInitializeSystem();
  8208.            /* set up a NOATTRIBUTE virtual window */
  8209.            vw1 = VirtualInitialize(NOATTRIBUTE,/* virt. window type */
  8210.                                    30,  /* Number of rows */
  8211.                                    80,  /* Number of cols */
  8212.                                    0);  /* Attribute      */
  8213.  
  8214.            /* set up an ATTRIBUTE virtual window */
  8215.            vw2 = VirtualInitialize(ATTRIBUTE, /* virtual window type */
  8216.                                    30,        /* Number of rows */
  8217.                                    100,       /* Number of cols */
  8218.                                    NORM);     /* Attribute      */
  8219.  
  8220.            if (vw1 == (VWPOINTER)0 ||
  8221.                vw2 == (VWPOINTER)0 ) /* Check if allocation worked */
  8222.              printf(
  8223.              "Error in allocating virtual window."
  8224.  
  8225.  
  8226.  
  8227.          Page 123          The C Window Library               Page 123
  8228.  
  8229.              "The error number is %d"", window_error_code);
  8230.          }
  8231.  
  8232.  
  8233.          In the above program, the VirtualInitialize() function is
  8234.          called.  This function allocates memory for the virtual
  8235.          window, and does other initializations.  Once this function
  8236.          is called, you can write to and read characters from the
  8237.          virtual window.
  8238.  
  8239.          Notice that the first argument to VirtualInitialize() is
  8240.          either the constant NOATTRIBUTE or ATTRIBUTE.
  8241.  
  8242.          Also note that there is a check to see whether the virtual
  8243.          windows could be allocated.   If there are no errors,
  8244.          VirtualInitialize() returns a valid VWPOINTER.  If there are
  8245.          errors, VirtualInitialize() returns a null VWPOINTER and sets
  8246.          the global variable window_error_code to one of the
  8247.          following:
  8248.  
  8249.          NO_HEAP_MEM if there is not enough memory to allocate for the
  8250.          virtual window.
  8251.  
  8252.          MAX_V_WINDOW if there are already 256 virtual windows
  8253.          defined.
  8254.  
  8255.  
  8256.  
  8257.  
  8258.  
  8259.  
  8260.  
  8261.  
  8262.  
  8263.  
  8264.  
  8265.  
  8266.  
  8267.  
  8268.  
  8269.  
  8270.  
  8271.  
  8272.  
  8273.  
  8274.  
  8275.  
  8276.  
  8277.  
  8278.  
  8279.  
  8280.  
  8281.  
  8282.  
  8283.  
  8284.  
  8285.  
  8286.  
  8287.          Page 124          The C Window Library               Page 124
  8288.  
  8289.               ASSIGNING VIEWPORTS AND CLOSING VIEWPORTS
  8290.               -----------------------------------------
  8291.  
  8292.          For a virtual window to have any useful purpose, it should be
  8293.          displayed on the screen.  However the virtual window may be
  8294.          larger than the physical screen.  The problem is solved by
  8295.          using normal windows to display parts of the virtual window.
  8296.  
  8297.  
  8298.  
  8299.          WindowAssignToVirtual()
  8300.          -----------------------
  8301.  
  8302.          To turn a window into a viewport onto a virtual window, you
  8303.          use the WindowAssignToVirtual() function.
  8304.  
  8305.          Here is the prototype:
  8306.  
  8307.          int WindowAssignToVirtual(WPOINTER w, VWPOINTER vw,
  8308.                                    unsigned row, unsigned col)
  8309.  
  8310.          The first argument is the window that will be turned into a
  8311.          viewport.  The second argument is the virtual window that w
  8312.          will be assigned to.  The third and fourth arguments are the
  8313.          (row,col) of the virtual window.  This position is where the
  8314.          upper left hand corner of the viewport's text area will be
  8315.          placed.
  8316.  
  8317.          To illustrate this, here is a sample call to
  8318.          WindowAssignToVirtual():
  8319.  
  8320.                 WindowAssignToVirtual(w,vw,5,10)
  8321.  
  8322.          The following description shows how this is to be
  8323.          interpreted:
  8324.  
  8325.                                   VIRTUAL WINDOW
  8326.           ------------------------------------------------------------
  8327.          |(1,1)                                                100,1)|
  8328.          |                                                           |
  8329.          |       (5,10) of virtual window is equivalent to (1,1) of  |
  8330.          |         |    the viewport.                                |
  8331.          |         v                                                 |
  8332.          |         -----------------------                           |
  8333.          |         |(1,1) of the viewport|                           |
  8334.          |         |                     |                           |
  8335.          |         |   VIEWPORT WINDOW   |                           |
  8336.          |         |(14,1)        (14,30)|                           |
  8337.          |         -----------------------                           |
  8338.          |                                                           |
  8339.          |(100,1)                                          (100,100) |
  8340.           ------------------------------------------------------------
  8341.  
  8342.  
  8343.          The viewport relative position of (1,1) is located at (5,10)
  8344.  
  8345.  
  8346.  
  8347.          Page 125          The C Window Library               Page 125
  8348.  
  8349.          of the virtual window.
  8350.  
  8351.          Example:
  8352.  
  8353.          #include "window.h"
  8354.  
  8355.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8356.          VWPOINTER vw;          /* virtual window pointers */
  8357.          WPOINTER w;
  8358.          main()
  8359.          {
  8360.            WindowInitializeSystem();
  8361.            WindowSaveInitial(0);
  8362.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8363.            w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,
  8364.                                 SINGLEBOX);
  8365.            WindowOpen(w);
  8366.            WindowDisplay(w,1,NOEFFECT);
  8367.            VirtualWriteString(vw,"This is a string",1,1);
  8368.  
  8369.            WindowAssignToVirtual(w,vw,1,1);  /* Assign viewport
  8370.                                                 to virtual window
  8371.                                               */
  8372.          }
  8373.  
  8374.          The above program opens a virtual window, vw, and opens a
  8375.          normal window, w.  In the above example, the
  8376.          VirtualWriteString() function is used to write strings to the
  8377.          virtual window.  See the WRITING TEXT TO VIRTUAL WINDOWS
  8378.          section for more information on VirtualWriteString().
  8379.  
  8380.          Once a window is turned into a viewport, nothing is stopping
  8381.          you from using the other window functions.  You can still use
  8382.          WindowWriteString(), WindowMove(), WindowPrintf(), etc.
  8383.          Writing text to a viewport window via the normal window
  8384.          functions does not effect the virtual window in any way.
  8385.  
  8386.          If there are no errors, WindowAssignToVirtual() returns
  8387.          NO_ERROR.  If there are errors, WindowAssignToVirtual()
  8388.          returns the following values:
  8389.  
  8390.          BAD_WINDOW if the window does not exist.
  8391.  
  8392.          BAD_V_WINDOW if the virtual window does not exist.
  8393.  
  8394.          WINDOW_NOT_OPEN if the window is not open for writing (use
  8395.          WindowOpen()).
  8396.  
  8397.  
  8398.          Out of bounds Coordinates
  8399.          -------------------------
  8400.  
  8401.          The next question is "What do you do if the coordinates given
  8402.          in WindowAssignToVirtual() are out of bounds of the range of
  8403.          the virtual window?".  For instance, if the virtual window
  8404.  
  8405.  
  8406.  
  8407.          Page 126          The C Window Library               Page 126
  8408.  
  8409.          has 100 rows, but the call to WindowAssignToVirtual()
  8410.          specifies row 97, and the viewport itself has a height of 10
  8411.          rows.  The window manager will fill the viewport with as much
  8412.          of the virtual window as possible, and will clear the
  8413.          contents of the viewport that are not inside the virtual
  8414.          window.
  8415.  
  8416.          Here is another view of what happens in this case:
  8417.  
  8418.  
  8419.                                 VIRTUAL WINDOW
  8420.           ----------------------------------------------------------
  8421.          |(1,1)                                             (100,1)|
  8422.          |                                                         |
  8423.          |       (97,10) of virtual window is same as (1,1) of     |
  8424.          |         |     the viewport window.                      |
  8425.          |         v                                               |
  8426.          |         -----------------------                         |
  8427.          |         |(1,1) of the viewport|                         |
  8428.          |         |                     |                         |
  8429.          |(100,1)  |   VIEWPORT WINDOW   |               (100,100) |
  8430.          -----------------------------------------------------------
  8431.                    |This portion of the  |
  8432.                    |  window is cleared  |
  8433.                    -----------------------
  8434.  
  8435.          The above picture shows a viewport that is partially
  8436.          contained in the virtual window.  The contents of the window
  8437.          above the last row of the virtual window is updated, while
  8438.          the portion of the viewport below the line is cleared.
  8439.  
  8440.  
  8441.  
  8442.  
  8443.          WindowCloseViewport()
  8444.          ---------------------
  8445.  
  8446.          To turn a viewport back to a normal window,
  8447.          WindowCloseViewport() is called.  Here is the prototype:
  8448.  
  8449.          int WindowCloseViewport(WPOINTER w, int hide, int effect)
  8450.  
  8451.          where w is the viewport to be turned back into a regular
  8452.          window.  When this function is called, the window w is
  8453.          cleared with its own video attribute.  The second argument
  8454.          tells if the window is to be hidden. If hide is 1, the window
  8455.          is hidden.  If it is 0, the window remains on the screen.
  8456.          The effect argument is a special effect to use when hiding
  8457.          the window.  A list of special effects are defined in the
  8458.          DISPLAYING WINDOWS section.  This function DOES NOT close the
  8459.          virtual window or does a WindowClose() to the viewport
  8460.          window.
  8461.  
  8462.  
  8463.  
  8464.  
  8465.  
  8466.  
  8467.          Page 127          The C Window Library               Page 127
  8468.  
  8469.          Example:
  8470.  
  8471.  
  8472.          #include "window.h"
  8473.  
  8474.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8475.          VWPOINTER vw;          /* virtual window pointers */
  8476.          WPOINTER w;
  8477.          main()
  8478.          {
  8479.            WindowInitializeSystem();
  8480.            WindowSaveInitial(0);
  8481.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8482.            w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  8483.            WindowOpen(w);
  8484.            WindowDisplay(w,1,NOEFFECT);
  8485.            VirtualWriteString(vw,"This is a string",1,1);
  8486.            WindowAssignToVirtual(w,vw,1,1);
  8487.            GET_KEY();
  8488.            WindowCloseViewport(w,1,NOEFFECT);
  8489.            GETKEY();
  8490.          }
  8491.  
  8492.  
  8493.          The example above opens a virtual windows and a normal.  It
  8494.          then assigns the windows to the virtual window by calling
  8495.          WindowAssignToVirtual().  The program then unassigns the
  8496.          viewport by calling WindowCloseViewport().
  8497.  
  8498.          If there are no errors, WindowCloseViewport() returns
  8499.          NO_ERROR.  If there are errors, WindowCloseViewport() returns
  8500.          the following values:
  8501.  
  8502.          BAD_WINDOW if the window does not exist.
  8503.  
  8504.          BAD_V_WINDOW if the virtual window that w is a viewport on
  8505.          does not exist.
  8506.  
  8507.          WINDOW_NOT_OPEN if the window is not open for writing (use
  8508.          WindowOpen()).
  8509.  
  8510.  
  8511.  
  8512.  
  8513.  
  8514.  
  8515.  
  8516.  
  8517.  
  8518.  
  8519.  
  8520.  
  8521.  
  8522.  
  8523.  
  8524.  
  8525.  
  8526.  
  8527.          Page 128          The C Window Library               Page 128
  8528.  
  8529.                    WRITING TEXT TO VIRTUAL WINDOWS
  8530.                    -------------------------------
  8531.  
  8532.          There are several functions that write strings to virtual
  8533.          windows.  They are divided into two groups: functions that
  8534.          take null terminated strings as arguments, and functions that
  8535.          use character buffers and a length argument.
  8536.  
  8537.          When any of the text functions are called, any viewport that
  8538.          is displaying any portion of the virtual window that has been
  8539.          changed will display the update.
  8540.  
  8541.  
  8542.          Null Terminated String Functions
  8543.          --------------------------------
  8544.  
  8545.          VirtualWriteString()
  8546.          --------------------
  8547.  
  8548.          The VirtualWriteString() function writes a null terminated to
  8549.          a virtual window at a specific row and column of the virtual
  8550.          window.  Here is the prototype:
  8551.  
  8552.          int VirtualWriteString(VWPOINTER vw, char *string,
  8553.                                 unsigned row, unsigned col)
  8554.  
  8555.          The first argument is the virtual window pointer.  The second
  8556.          argument is the string to write.  The third and fourth
  8557.          arguments are the row and column of the virtual window that
  8558.          the string is to be written to.  If the string will exceed
  8559.          the boundaries of the virtual window, the string is
  8560.          truncated.
  8561.  
  8562.          Example:
  8563.  
  8564.          #include "window.h"
  8565.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8566.          VWPOINTER vw;          /* virtual window pointers */
  8567.          WPOINTER w1, w2;
  8568.          main()
  8569.          {
  8570.            WindowInitializeSystem();
  8571.            WindowSaveInitial(0);
  8572.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8573.            w1 = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,
  8574.                                  SINGLEBOX);
  8575.            w2 = WindowInitialize(BORDER,13,1,20,10,NORM,NORM,
  8576.                                  DOUBLEBOX);
  8577.            WindowOpen(w1);
  8578.            WindowOpen(w2);
  8579.            WindowDisplay(w1,1,NOEFFECT);
  8580.            WindowDisplay(w2,2,NOEFFECT);
  8581.            VirtualWriteString(vw,"This is a string",1,1);
  8582.  
  8583.            WindowAssignToVirtual(w1,vw,1,1);
  8584.  
  8585.  
  8586.  
  8587.          Page 129          The C Window Library               Page 129
  8588.  
  8589.            WindowAssignToVirtual(w2,vw,1,10);
  8590.          }
  8591.  
  8592.  
  8593.          The example above writes the string "This is a string" to the
  8594.          virtual window at row 1, column 1.  The windows w1 and w2 are
  8595.          viewports on the virtual window vw.  The window w1 is located
  8596.          at (1,1) of the virtual window, while w2 is located at (1,10)
  8597.          of the virtual window.  The window w1 will display "This is a
  8598.          string", but w2 will only display "string" since it is
  8599.          situated at column 10 of the virtual window.
  8600.  
  8601.  
  8602.          If there are no errors, VirtualWriteString() returns
  8603.          NO_ERROR.
  8604.  
  8605.          If there are errors, VirtualWriteString() returns the
  8606.          following values:
  8607.  
  8608.  
  8609.          BAD_V_WINDOW if the virtual window does not exist.
  8610.  
  8611.          V_WINDOW_BOUND if the either row or col is out of bounds of
  8612.          the virtual window.
  8613.  
  8614.  
  8615.  
  8616.  
  8617.          VirtualWriteStringAttr()
  8618.          ------------------------
  8619.  
  8620.          The VirtualWriteStringAttr() works the same way as the
  8621.          VirtualWriteString() except that a video attribute is used.
  8622.          Here is the prototype:
  8623.  
  8624.          int VirtualWriteStringAttr(VWPOINTER vw, char *string,
  8625.                                     unsigned row, unsigned col,
  8626.                                     int attr)
  8627.  
  8628.          The last argument is the video attribute to use.  If the
  8629.          virtual window is NOATTRIBUTE, the attribute is ignored, and
  8630.          only the string is written.  Any viewports that are assigned
  8631.          to NOATTRIBUTE virtual windows will not reflect the change in
  8632.          the attribute.
  8633.  
  8634.          Example:
  8635.  
  8636.          #include "window.h"
  8637.          #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  8638.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  8639.          VWPOINTER vw;          /* virtual window pointers */
  8640.          WPOINTER w;
  8641.          main()
  8642.          {
  8643.            WindowInitializeSystem();
  8644.  
  8645.  
  8646.  
  8647.          Page 130          The C Window Library               Page 130
  8648.  
  8649.            WindowSaveInitial(0);
  8650.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8651.            w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,
  8652.                                 SINGLEBOX);
  8653.            WindowOpen(w);
  8654.            WindowDisplay(w,1,NOEFFECT);
  8655.            VirtualWriteStringAttr(vw,"This is a string",1,1,REVERSE);
  8656.            WindowAssignToVirtual(w,vw,1,1);
  8657.          }
  8658.  
  8659.  
  8660.          The example above writes the string "This is a string" in the
  8661.          virtual window with a video attribute defined by the constant
  8662.          REVERSE.
  8663.  
  8664.          If there are no errors, VirtualWriteStringAttr() returns
  8665.          NO_ERROR.
  8666.  
  8667.          If there are errors, VirtualWriteStringAttr() returns the
  8668.          following values:
  8669.  
  8670.          BAD_V_WINDOW if the virtual window does not exist.
  8671.  
  8672.          V_WINDOW_BOUND if the either row or col is out of bounds of
  8673.          the virtual window.
  8674.  
  8675.          NO_ATTRIB if the virtual window is NOATTRIBUTE.  If this
  8676.          error occurs, only the string is written.
  8677.  
  8678.  
  8679.  
  8680.  
  8681.          VirtualWriteCenterString()
  8682.          --------------------------
  8683.  
  8684.          The VirtualWriteCenterString() writes a centered string in a
  8685.          virtual window.  Here is the prototype:
  8686.  
  8687.          int VirtualWriteCenterString(VWPOINTER vw, char *string,
  8688.                                       unsigned row)
  8689.  
  8690.          The row argument is the row to center the string on.
  8691.  
  8692.  
  8693.          Example:
  8694.  
  8695.          #include "window.h"
  8696.          #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  8697.          VWPOINTER vw;          /* virtual window pointers */
  8698.          WPOINTER w;
  8699.  
  8700.          main()
  8701.          {
  8702.            WindowInitializeSystem();
  8703.            WindowSaveInitial(0);
  8704.  
  8705.  
  8706.  
  8707.          Page 131          The C Window Library               Page 131
  8708.  
  8709.            vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  8710.            w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  8711.            WindowOpen(w);
  8712.            WindowDisplay(w,1,NOEFFECT);
  8713.            VirtualWriteCenterString(vw,"This is a string",1);
  8714.            WindowAssignToVirtual(w,vw,1,1);
  8715.          }
  8716.  
  8717.  
  8718.          The above example illustrates the use of
  8719.          VirtualWriteCenterString().  The viewport window w is just
  8720.          used as a guide to display what has happened.
  8721.  
  8722.          If there are no errors, VirtualWriteCenterString() returns
  8723.          NO_ERROR.
  8724.  
  8725.          If there are errors, VirtualWriteCenterString() returns the
  8726.          following values:
  8727.  
  8728.  
  8729.          BAD_V_WINDOW if the virtual window does not exist.
  8730.  
  8731.          V_WINDOW_BOUND if the row is out of bounds of the virtual
  8732.          window.
  8733.  
  8734.  
  8735.  
  8736.  
  8737.          VirtualWriteCenterStringAttr()
  8738.          ------------------------------
  8739.  
  8740.  
  8741.          The VirtualWriteCenterStringAttr() function works the same
  8742.          way as VirtualWriteCenterString() except that a video
  8743.          attribute is specified.  Here is the prototype:
  8744.  
  8745.          int VirtualWriteCenterStringAttr(VWPOINTER vw, char *string,
  8746.                                           unsigned row, int attr)
  8747.  
  8748.          The attr argument is the video attribute to use.  If the
  8749.          virtual window is NOATTRIBUTE, the attribute is ignored and
  8750.          only the string is written to the virtual window.
  8751.  
  8752.  
  8753.          #include "window.h"
  8754.  
  8755.          #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  8756.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  8757.          VWPOINTER vw;          /* virtual window pointers */
  8758.          WPOINTER w;
  8759.          main()
  8760.          {
  8761.            WindowInitializeSystem();
  8762.            WindowSaveInitial(0);
  8763.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8764.  
  8765.  
  8766.  
  8767.          Page 132          The C Window Library               Page 132
  8768.  
  8769.            w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  8770.            WindowOpen(w);
  8771.            WindowDisplay(w,1,NOEFFECT);
  8772.            VirtualWriteCenterStringAttr(vw,"This is a string",1,
  8773.                                         REVERSE);
  8774.            WindowAssignToVirtual(w,vw,1,1);
  8775.          }
  8776.  
  8777.  
  8778.          If there are no errors, VirtualWriteCenterStringAttr()
  8779.          returns NO_ERROR.
  8780.  
  8781.          If there are errors, VirtualWriteCenterStringAttr() returns
  8782.          the following values:
  8783.  
  8784.          BAD_V_WINDOW if the virtual window does not exist.
  8785.  
  8786.          V_WINDOW_BOUND if the row is out of bounds of the virtual
  8787.          window.
  8788.  
  8789.          NO_ATTRIB if the virtual window is NOATTRIBUTE.  If this
  8790.          error occurs, only the string is written.
  8791.  
  8792.  
  8793.  
  8794.  
  8795.          VirtualWriteStringCC()
  8796.          ----------------------
  8797.  
  8798.          The VirtualWriteStringCC() function centers and writes a
  8799.          string around a column of the virtual window (the CC stands
  8800.          for Centered Column).  If the string is longer than the width
  8801.          of the virtual window, the string is placed on column 1 is
  8802.          clipped at the right edge of the virtual window.  Here is the
  8803.          prototype:
  8804.  
  8805.          int VirtualWriteStringCC(VWPOINTER vw, char *string,
  8806.                                   unsigned row, unsigned col)
  8807.  
  8808.          The first argument is the window.  The second argument is the
  8809.          string. The third argument is the row to write the string,
  8810.          and the last argument is the column to center the string on.
  8811.  
  8812.          Example:
  8813.  
  8814.          #include "window.h"
  8815.          #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  8816.          VWPOINTER vw;          /* virtual window pointers */
  8817.          WPOINTER w;
  8818.          main()
  8819.          {
  8820.            WindowInitializeSystem();
  8821.            WindowSaveInitial(0);
  8822.            vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  8823.            w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  8824.            WindowOpen(w);
  8825.  
  8826.  
  8827.          Page 133          The C Window Library               Page 133
  8828.  
  8829.            WindowDisplay(w,1,NOEFFECT);
  8830.            VirtualWriteStringCC(vw,"This",1,10);
  8831.            VirtualWriteStringCC(vw,"is",2,10);
  8832.            VirtualWriteStringCC(vw,"centered",3,10);
  8833.            VirtualWriteStringCC(vw,"around",4,10);
  8834.            VirtualWriteStringCC(vw,"column",5,10);
  8835.            VirtualWriteStringCC(vw,"10",6,10);
  8836.            WindowAssignToVirtual(w,vw,1,1);
  8837.          }
  8838.  
  8839.  
  8840.          The example above writes the text centered around column 10
  8841.          of the virtual window w.
  8842.  
  8843.          The return values for VirtualWriteStringCC() are the same as
  8844.          VirtualWriteString().
  8845.  
  8846.  
  8847.  
  8848.  
  8849.  
  8850.          VirtualWriteStringCCAttr()
  8851.          --------------------------
  8852.  
  8853.          The VirtualWriteStringCCAttr() works the same way as the
  8854.          VirtualWriteStringCC() function except that a video attribute
  8855.          is specified.  Here is the prototype:
  8856.  
  8857.          int VirtualWriteStringCCAttr(VWPOINTER vw, char *string,
  8858.                                       unsigned row, unsigned col,
  8859.                                       int attr)
  8860.  
  8861.          The attribute to use is the last argument.  If the virtual
  8862.          window is NOATTRIBUTE, the attr argument is ignored, and only
  8863.          the string is written to the virtual window.
  8864.  
  8865.          Example:
  8866.  
  8867.          #include "window.h"
  8868.  
  8869.          #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  8870.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  8871.  
  8872.          VWPOINTER vw;          /* virtual window pointers */
  8873.          WPOINTER w;
  8874.          main()
  8875.          {
  8876.            WindowInitializeSystem();
  8877.            WindowSaveInitial(0);
  8878.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8879.            w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  8880.            WindowOpen(w);
  8881.            WindowDisplay(w,1,NOEFFECT);
  8882.            VirtualWriteStringCCAttr(vw,"This",1,10,REVERSE);
  8883.            VirtualWriteStringCCAttr(vw,"is",2,10,REVERSE);
  8884.  
  8885.  
  8886.  
  8887.          Page 134          The C Window Library               Page 134
  8888.  
  8889.            VirtualWriteStringCCAttr(vw,"centered",3,10,REVERSE);
  8890.            VirtualWriteStringCCAttr(vw,"around",4,10,REVERSE);
  8891.            VirtualWriteStringCCAttr(vw,"column",5,10,REVERSE);
  8892.            VirtualWriteStringCCAttr(vw,"10",6,10,REVERSE);
  8893.            WindowAssignToVirtual(w,vw,1,1);
  8894.          }
  8895.  
  8896.  
  8897.          The return values for VirtualWriteStringCCAttr() are the same
  8898.          as VirtualWriteStringAttr().
  8899.  
  8900.  
  8901.  
  8902.          VirtualWriteStringRJ()
  8903.          ----------------------
  8904.  
  8905.          The VirtualWriteStringRJ() function writes a right justified
  8906.          string in a virtual window.  Here is the prototype:
  8907.  
  8908.          int VirtualWriteStringRJ(WPOINTER w, char *string,
  8909.                                   unsigned row, unsigned col)
  8910.  
  8911.          The first argument is the virtual window.  The second
  8912.          argument is the string.  The third argument is the row to
  8913.          write the string, and the last argument is the column to
  8914.          place the right edge of the string.
  8915.  
  8916.  
  8917.          Example:
  8918.  
  8919.          #include "window.h"
  8920.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8921.  
  8922.           VWPOINTER vw;          /* virtual window pointers */
  8923.           WPOINTER w;
  8924.           main()
  8925.           {
  8926.             WindowInitializeSystem();
  8927.             WindowSaveInitial(0);
  8928.             vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  8929.             w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,
  8930.                                  SINGLEBOX);
  8931.             WindowOpen(w);
  8932.             WindowDisplay(w,1,NOEFFECT);
  8933.             VirtualWriteStringRJ(vw,"This",1,10);
  8934.             VirtualWriteStringRJ(vw,"is",2,10);
  8935.             VirtualWriteStringRJ(vw,"right",3,10);
  8936.             VirtualWriteStringRJ(vw,"justified",4,10);
  8937.             VirtualWriteStringRJ(vw,"on ",5,10);
  8938.             VirtualWriteStringRJ(vw,"column",6,10);
  8939.             VirtualWriteStringRJ(vw,"10",7,10);
  8940.             WindowAssignToVirtual(w,vw,1,1);
  8941.           }
  8942.  
  8943.  
  8944.          The example above writes the text right justified on column
  8945.  
  8946.  
  8947.          Page 135          The C Window Library               Page 135
  8948.  
  8949.          10 of the virtual window.
  8950.  
  8951.          The return values for VirtualWriteStringRJ() are the same as
  8952.          VirtualWriteString().
  8953.  
  8954.  
  8955.  
  8956.  
  8957.          VirtualWriteStringRJAttr()
  8958.          --------------------------
  8959.  
  8960.          The VirtualWriteStringRJAttr() writes a right justified
  8961.          string in a virtual window, and allows you to specify a video
  8962.          attribute. Here is the prototype:
  8963.  
  8964.          int VirtualWriteStringRJAttr(WPOINTER w, char *string,
  8965.                                       unsigned row, unsigned col,
  8966.                                       int attr)
  8967.  
  8968.          The last argument is the attribute to use.
  8969.  
  8970.  
  8971.          Example:
  8972.  
  8973.  
  8974.          #include "window.h"
  8975.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8976.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  8977.  
  8978.          VWPOINTER vw;          /* virtual window pointers */
  8979.          WPOINTER w;
  8980.          main()
  8981.          {
  8982.            WindowInitializeSystem();
  8983.            WindowSaveInitial(0);
  8984.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8985.            w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  8986.            WindowOpen(w);
  8987.            WindowDisplay(w,1,NOEFFECT);
  8988.            VirtualWriteStringRJAttr(vw,"This",1,10,REVERSE);
  8989.            VirtualWriteStringRJAttr(vw,"is",2,10,REVERSE);
  8990.            VirtualWriteStringRJAttr(vw,"right",3,10,REVERSE);
  8991.            VirtualWriteStringRJAttr(vw,"justified",4,10,REVERSE);
  8992.            VirtualWriteStringRJAttr(vw,"on ",5,10,REVERSE);
  8993.            VirtualWriteStringRJAttr(vw,"column",6,10,REVERSE);
  8994.            VirtualWriteStringRJAttr(vw,"10",7,10,REVERSE);
  8995.            WindowAssignToVirtual(w,vw,1,1);
  8996.          }
  8997.  
  8998.  
  8999.          The example above writes the text right justified on column
  9000.          10 of the virtual window.  If the virtual window is
  9001.          NOATTRIBUTE, only the string is written.
  9002.  
  9003.          The return values for VirtualWriteStringRJAttr() are the same
  9004.          as VirtualWriteStringAttr().
  9005.  
  9006.  
  9007.          Page 136          The C Window Library               Page 136
  9008.  
  9009.          Length Controlled Functions
  9010.          ---------------------------
  9011.  
  9012.  
  9013.  
  9014.          VirtualWriteCharacters()
  9015.          ------------------------
  9016.  
  9017.          The VirtualWriteCharacters() writes a specified number of
  9018.          characters from a buffer to the virtual window.  Here is the
  9019.          prototype:
  9020.  
  9021.  
  9022.          int VirtualWriteCharacters(VWPOINTER vw, char *buffer,
  9023.                                     unsigned row, unsigned col,
  9024.                                     unsigned length)
  9025.  
  9026.  
  9027.          The first argument is the virtual window.  The second
  9028.          argument is the buffer where the characters are stored.  The
  9029.          third and fourth arguments are the (row,col) of where the
  9030.          characters will be placed in the virtual window.  The last
  9031.          argument is the number of characters from buffer that will be
  9032.          written.
  9033.  
  9034.  
  9035.          Example:
  9036.  
  9037.  
  9038.          #include "window.h"
  9039.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9040.  
  9041.          WPOINTER w;
  9042.          VWPOINTER vw;
  9043.          char buf[] = "Hello World!!";
  9044.  
  9045.          main()
  9046.          {
  9047.            WindowInitializeSystem();
  9048.            WindowSaveInitial(0);
  9049.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  9050.            vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  9051.            WindowOpen(w);
  9052.            WindowDisplay(w,1,NOEFFECT);
  9053.            VirtualWriteCharacters(vw,buf,1,1,11);
  9054.            VirtualWriteCharacters(vw,buf,2,1,13);
  9055.            WindowAssignToVirtual(w,vw,1,1);
  9056.          }
  9057.  
  9058.  
  9059.          The return values for VirtualWriteCharacters() are the same
  9060.          as VirtualWriteString().
  9061.  
  9062.  
  9063.  
  9064.  
  9065.  
  9066.  
  9067.          Page 137          The C Window Library               Page 137
  9068.  
  9069.          VirtualWriteAttributes()
  9070.          ------------------------
  9071.  
  9072.          The VirtualWriteAttributes() writes a specified number of
  9073.          attributes from a buffer to the virtual window.  Here is the
  9074.          prototype:
  9075.  
  9076.  
  9077.          int VirtualWriteAttributes(VWPOINTER vw, char *buffer,
  9078.                                     unsigned row, unsigned col,
  9079.                                     unsigned length)
  9080.  
  9081.  
  9082.          The first argument is the virtual window.  The second
  9083.          argument is the buffer where the attributes are stored.  The
  9084.          third and fourth arguments are the (row,col) of where the
  9085.          attributes will be placed in the virtual window.  The last
  9086.          argument is the number of attributes from buffer that will be
  9087.          written.  If the window is NOATTRIBUTE, this function does
  9088.          nothing.
  9089.  
  9090.          Example:
  9091.  
  9092.  
  9093.          #include "window.h"
  9094.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9095.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  9096.          WPOINTER w;
  9097.          VWPOINTER vw;
  9098.          char buf[13];
  9099.  
  9100.          main()
  9101.          {
  9102.            int i;
  9103.            WindowInitializeSystem();
  9104.            WindowSaveInitial(0);
  9105.            for (i=0;i<13;i++)
  9106.              if (i % 2)
  9107.                buf[i] = NORM;
  9108.              else
  9109.                buf[i] = REVERSE;
  9110.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  9111.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  9112.            WindowOpen(w);
  9113.            WindowDisplay(w,1,NOEFFECT);
  9114.            VirtualWriteString(vw,"Hello World!!",1,1);
  9115.            VirtualWriteAttributes(vw,buf,1,1,13);
  9116.            WindowAssignToVirtual(w,vw,1,1);
  9117.          }
  9118.  
  9119.  
  9120.          The return values for VirtualWriteAttributes() are the same
  9121.          as VirtualWriteStringAttr().
  9122.  
  9123.  
  9124.  
  9125.  
  9126.  
  9127.          Page 138          The C Window Library               Page 138
  9128.  
  9129.          VirtualWriteCharAndAttr()
  9130.          -------------------------
  9131.  
  9132.          The VirtualWriteCharAndAttr() function writes a string of
  9133.          character/attribute pairs to a virtual window.  Use this
  9134.          function if you have created a string of character/attribute
  9135.          pairs, and want to output them easily.  The string consists
  9136.          of character and attributes in the following manner:
  9137.  
  9138.                   char-attr-char-attr...
  9139.  
  9140.          Each character is followed by its corresponding video
  9141.          attribute.  Here is the prototype:
  9142.  
  9143.          int VirtualWriteCharAndAttr(VWPOINTER vw, char *buffer,
  9144.                                      unsigned row, unsigned col,
  9145.                                      unsigned length)
  9146.  
  9147.          The first argument is the virtual window. The second is the
  9148.          buffer where the character and attributes are stored.  The
  9149.          third and fourth is the (row,col) position in the virtual
  9150.          window to write, and the length argument is the number of
  9151.          character/attribute pairs from the buffer to write.  Please
  9152.          note the difference in the meaning of the length argument in
  9153.          this function as opposed to its use in the preceding
  9154.          functions.
  9155.  
  9156.          If the virtual window is NOATTRIBUTE, nothing is written to
  9157.          the virtual window.
  9158.  
  9159.          Example:
  9160.  
  9161.          #include "window.h"
  9162.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9163.  
  9164.          WPOINTER w;
  9165.          VWPOINTER vw;
  9166.          char buf[26];
  9167.          char *str = "Hello World!!";
  9168.          main()
  9169.          {
  9170.            int i;
  9171.            WindowInitializeSystem();
  9172.            WindowSaveInitial(0);
  9173.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  9174.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  9175.            WindowOpen(w);
  9176.            WindowDisplay(w,1,NOEFFECT);
  9177.  
  9178.            for (i=0;i<26;i+=2,str++)
  9179.            {
  9180.              buf[i] = *str;
  9181.              buf[i+1] = NORM;
  9182.            }
  9183.            VirtualWriteCharAndAttr(vw,buf,1,1,13);
  9184.  
  9185.  
  9186.  
  9187.          Page 139          The C Window Library               Page 139
  9188.  
  9189.            WindowAssignToVirtual(w,vw,1,1);
  9190.          }
  9191.  
  9192.  
  9193.          The return values for VirtualWriteCharAndAttr() are the same
  9194.          as VirtualWriteStringAttr().
  9195.  
  9196.  
  9197.  
  9198.          VirtualWriteRepeatAttribute()
  9199.          -----------------------------
  9200.  
  9201.          The VirtualWriteRepeatAttribute() function writes an
  9202.          attribute a specified number of times to a virtual window.
  9203.          Here is a prototype:
  9204.  
  9205.  
  9206.          int VirtualWriteRepeatAttribute(VWPOINTER vw, int attr,
  9207.                                          unsigned row, unsigned col,
  9208.                                          int count)
  9209.  
  9210.          The attr argument is the attribute to use.  The count
  9211.          argument specifies the number of times to write the attribute
  9212.          attr to the virtual window starting at (row,col).  If the
  9213.          virtual window is NOATTRIBUTE, this function returns an
  9214.          error.
  9215.  
  9216.  
  9217.          Example:
  9218.  
  9219.          #include "window.h"
  9220.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9221.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  9222.  
  9223.          WPOINTER w;
  9224.          VWPOINTER vw;
  9225.          main()
  9226.          {
  9227.            WindowInitializeSystem();
  9228.            WindowSaveInitial(0);
  9229.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  9230.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  9231.            WindowOpen(w);
  9232.            WindowDisplay(w,1,NOEFFECT);
  9233.            VirtualWriteString(vw,"Hello World!!",1,1);
  9234.            VirtualWriteRepeatAttribute(vw,REVERSE,1,1,13);
  9235.            WindowAssignToVirtual(w,vw,1,1);
  9236.          }
  9237.  
  9238.  
  9239.          The example above illustrates that the
  9240.          VirtualWriteRepeatAttribute() writes the REVERSE attribute 13
  9241.          times starting at row 1, column 1 of the virtual window w.
  9242.  
  9243.          The return values for VirtualWriteRepeatAttribute() are the
  9244.          same as VirtualWriteStringAttr().
  9245.  
  9246.  
  9247.          Page 140          The C Window Library               Page 140
  9248.  
  9249.          VirtualWriteRepeatCharacter()
  9250.          -----------------------------
  9251.  
  9252.          The VirtualWriteRepeatCharacter() function writes a character
  9253.          a specified number of times to a virtual window.  Here is a
  9254.          prototype:
  9255.  
  9256.  
  9257.          int VirtualWriteRepeatCharacter(WPOINTER w, int ch, int row,
  9258.                                          int col, int count)
  9259.  
  9260.  
  9261.          The count argument is the character to use.  The count
  9262.          argument specifies the number of times to write the character
  9263.          ch to the virtual window starting at (row,col).
  9264.  
  9265.          Example:
  9266.  
  9267.          #include "window.h"
  9268.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9269.  
  9270.          VWPOINTER vw;
  9271.          WPOINTER w;
  9272.  
  9273.          main()
  9274.          {
  9275.            WindowInitializeSystem();
  9276.            WindowSaveInitial(0);
  9277.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  9278.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  9279.            WindowOpen(w);
  9280.            WindowDisplay(w,1,NOEFFECT);
  9281.            VirtualWriteRepeatCharacter(vw,'a',1,1,5);
  9282.            VirtualWriteRepeatCharacter(vw,'b',2,1,5);
  9283.            VirtualWriteRepeatCharacter(vw,'c',3,1,5);
  9284.            WindowAssignToVirtual(w,vw,1,1);
  9285.          }
  9286.  
  9287.  
  9288.          The example above illustrates that the
  9289.          VirtualWriteRepeatCharacter() writes the letter 'a', 'b', and
  9290.          'c' 5 times on rows 1, 2, and 3 respectively.
  9291.  
  9292.          The return values for VirtualWriteRepeatCharacter() are the
  9293.          same as VirtualWriteString().
  9294.  
  9295.  
  9296.  
  9297.  
  9298.  
  9299.  
  9300.  
  9301.  
  9302.  
  9303.  
  9304.  
  9305.  
  9306.  
  9307.          Page 141          The C Window Library               Page 141
  9308.  
  9309.          Formatted Write Functions
  9310.          -------------------------
  9311.  
  9312.  
  9313.          Format String
  9314.          -------------
  9315.  
  9316.          These functions write formatted output to virtual windows
  9317.          just like the printf() function.  There are two functions
  9318.          that do this, namely VirtualPrintf() and VirtualPrintfAttr().
  9319.          These functions use a format string that is similar to the
  9320.          format string found in printf().  For example, %d, %s, %lf,
  9321.          etc. and most of the escape sequences are supported.  The
  9322.          list of escape sequences supported are as follows:
  9323.  
  9324.                                \n - newline
  9325.                                \t - tab
  9326.                                \r - carriage return
  9327.                                \x - hexadecimal
  9328.  
  9329.  
  9330.          Where Output is Placed
  9331.          ----------------------
  9332.  
  9333.          The row and column of where the string will be written is
  9334.          determined by the virtual window's logical cursor.  The
  9335.          logical cursor is advanced by both of these functions to one
  9336.          column position after the last character is printed.  If you
  9337.          want to start at a particular row and column of the window,
  9338.          you must move the cursor yourself by calling the
  9339.          VirtualMoveCursor() function.  This function is explained in
  9340.          the MOVING THE LOGICAL CURSOR section.
  9341.  
  9342.          When the virtual window is first initialized using
  9343.          VirtualInitialize(), the logical cursor is automatically
  9344.          moved to (1,1) of the virtual window.
  9345.  
  9346.  
  9347.  
  9348.          VirtualSetWrap()
  9349.          ----------------
  9350.  
  9351.          With these functions, any text that will exceed the
  9352.          boundaries of the window will be wrapped to the next line.
  9353.          If the output will exceed the last row of the window, the
  9354.          window is automatically scrolled up by one line.  This is the
  9355.          default action to take when characters exceed the right edge
  9356.          of the virtual window.  If you want the output clipped
  9357.          instead of wrapped, you must set the virtual window's wrap
  9358.          flag using the VirtualSetWrap() function.
  9359.  
  9360.          The VirtualSetWrap() function sets the virtual window's wrap
  9361.          flag to either on or off.  Here is the prototype:
  9362.  
  9363.                int VirtualSetWrap(VWPOINTER vw, int option)
  9364.  
  9365.  
  9366.  
  9367.          Page 142          The C Window Library               Page 142
  9368.  
  9369.          The second argument will be 0 if you want to turn the wrap
  9370.          flag off, or 1 if you want to turn it on.  If the wrap flag
  9371.          is off, the output generated by
  9372.  
  9373.  
  9374.          VirtualPrintf() and VirtualPrintfAttr() will be terminated
  9375.          when the right edge of the window is reached.  If the wrap
  9376.          flag is on, the output is wrapped to the next line when the
  9377.          right edge is reached.  Unlike regular windows, the output is
  9378.          not scrolled if the last line of the virtual window is
  9379.          reached.
  9380.  
  9381.          You can set the wrap flag to a virtual window at any time.
  9382.  
  9383.  
  9384.  
  9385.          VirtualPrintf()
  9386.          --------------
  9387.  
  9388.          The VirtualPrintf() function writes formatted output to the
  9389.          virtual window.  Here is the prototype:
  9390.  
  9391.            int VirtualPrintf(VWPOINTER vw, char *format [,arg1,...])
  9392.  
  9393.          The first argument is the virtual window.  The second
  9394.          argument is a format string.  The rest of the arguments are
  9395.          optional arguments that are written to the virtual window.
  9396.  
  9397.  
  9398.          Example:
  9399.  
  9400.          #include "window.h"
  9401.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9402.  
  9403.          WPOINTER w;
  9404.          VWPOINTER vw;
  9405.          int i = 3;
  9406.          double j = 5.6;
  9407.  
  9408.          main()
  9409.          {
  9410.            WindowInitializeSystem();
  9411.            WindowSaveInitial(0);
  9412.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  9413.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  9414.            WindowOpen(w);
  9415.            WindowDisplay(w,1,NOEFFECT);
  9416.            WindowAssignToVirtual(w,vw,1,1);
  9417.            VirtualPrintf(vw,"3+2 is equal to %d\n",3+2);
  9418.            GET_KEY();
  9419.            VirtualPrintf(vw,"i is equal to %d\nj is equal to %lf\n",
  9420.                          i,j);
  9421.          }
  9422.  
  9423.  
  9424.  
  9425.  
  9426.  
  9427.          Page 143          The C Window Library               Page 143
  9428.  
  9429.          The above example illustrates how VirtualPrintf() is used to
  9430.          print formatted strings to a virtual window.
  9431.  
  9432.          The return values for VirtualPrintf() are the same as
  9433.          VirtualWriteString().
  9434.  
  9435.  
  9436.  
  9437.  
  9438.          VirtualPrintfAttr()
  9439.          -------------------
  9440.  
  9441.          The VirtualPrintfAttr() function writes formatted output to
  9442.          the virtual window.  The difference between VirtualPrintf()
  9443.          and VirtualPrintfAttr() is that VirtualPrintfAttr() uses a
  9444.          video attribute specified as an argument.  Here is the
  9445.          prototype:
  9446.  
  9447.          int VirtualPrintfAttr(VWPOINTER vw, int attr,
  9448.                                char *format [,arg1,...])
  9449.  
  9450.          The first argument is the virtual window.  The second
  9451.          argument is the video attribute to use.  The third argument
  9452.          is the format string.  The rest of the arguments are optional
  9453.          arguments that are written to the virtual window.  If the
  9454.          virtual window is NOATTRIBUTE, only the string is written to
  9455.          the window.
  9456.  
  9457.          Example:
  9458.  
  9459.          #include "window.h"
  9460.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9461.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  9462.  
  9463.          WPOINTER w;
  9464.          VWPOINTER vw;
  9465.          int i = 3;
  9466.          double j = 5.6;
  9467.  
  9468.          main()
  9469.          {
  9470.            WindowInitializeSystem();
  9471.            WindowSaveInitial(0);
  9472.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  9473.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  9474.            WindowOpen(w);
  9475.            WindowDisplay(w,1,NOEFFECT);
  9476.            WindowAssignToVirtual(w,vw,1,1);
  9477.            VirtualPrintfAttr(vw,REVERSE,"3+2 is equal to %d\n",3+2);
  9478.            GET_KEY();
  9479.            VirtualPrintfAttr(vw,REVERSE,
  9480.                        "i is equal to %d\nj is equal to %lf\n",i,j);
  9481.          }
  9482.  
  9483.  
  9484.  
  9485.  
  9486.  
  9487.          Page 144          The C Window Library               Page 144
  9488.  
  9489.          The above example illustrates how VirtualPrintfAttr() is used
  9490.          to print formatted strings.
  9491.  
  9492.          The return values for VirtualPrintfAttr() are the same as
  9493.          VirtualWriteStringAttr().
  9494.  
  9495.  
  9496.  
  9497.  
  9498.  
  9499.  
  9500.  
  9501.  
  9502.  
  9503.  
  9504.  
  9505.  
  9506.  
  9507.  
  9508.  
  9509.  
  9510.  
  9511.  
  9512.  
  9513.  
  9514.  
  9515.  
  9516.  
  9517.  
  9518.  
  9519.  
  9520.  
  9521.  
  9522.  
  9523.  
  9524.  
  9525.  
  9526.  
  9527.  
  9528.  
  9529.  
  9530.  
  9531.  
  9532.  
  9533.  
  9534.  
  9535.  
  9536.  
  9537.  
  9538.  
  9539.  
  9540.  
  9541.  
  9542.  
  9543.  
  9544.  
  9545.  
  9546.  
  9547.          Page 145          The C Window Library               Page 145
  9548.  
  9549.            READING CHARACTERS AND ATTRIBUTES FROM VIRTUAL WINDOWS
  9550.            ------------------------------------------------------
  9551.  
  9552.  
  9553.          With The C Window Library, you can read the contents of a
  9554.          virtual window into a character buffer.  These functions
  9555.          provide the programmer with the contents of the virtual
  9556.          window at any time.  The functions to perform this are
  9557.          VirtualReadAttributes(), VirtualReadCharacters() and
  9558.          VirtualReadCharAndAttr().
  9559.  
  9560.  
  9561.  
  9562.          VirtualReadCharacters()
  9563.          -----------------------
  9564.  
  9565.          The VirtualReadCharacters() function reads the characters
  9566.          from a virtual window into a buffer.  Here is the prototype.
  9567.  
  9568.          int VirtualReadCharacters(VWPOINTER vw, char *buffer,
  9569.                                    unsigned row, unsigned col,
  9570.                                    unsigned length)
  9571.  
  9572.          The first argument is the virtual window.  The second
  9573.          argument is the buffer to store the characters in.  The third
  9574.          and fourth arguments are the (row,col) position in the
  9575.          virtual window to start reading from.  The last argument is
  9576.          the number of characters to read.
  9577.  
  9578.          You must make sure that buffer has enough room to hold all of
  9579.          the characters read in.
  9580.  
  9581.  
  9582.          Example:
  9583.  
  9584.          #include "window.h"
  9585.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9586.  
  9587.          VWPOINTER vw;
  9588.          char buf[14] = {0};      /* Null all elements of buf */
  9589.  
  9590.          main()
  9591.          {
  9592.            int i;
  9593.            WindowInitializeSystem();
  9594.            WindowSaveInitial(0);
  9595.            vw = VirtualInitialize(NOATTRIBUTE,10,80,NORM);
  9596.            VirtualWriteString(vw,"Hello World!!",1,1);
  9597.            VirtualReadCharacters(vw,buf,1,1,13);
  9598.          }
  9599.  
  9600.          The example above illustrates the use of
  9601.          VirtualReadCharacters(), which reads the virtual window's
  9602.          contents starting at (1,1).  This happens to be the string
  9603.          "Hello World!!".
  9604.  
  9605.  
  9606.  
  9607.          Page 146          The C Window Library               Page 146
  9608.  
  9609.          If the length exceeds the right edge of the virtual window,
  9610.          VirtualReadCharacters() will read up to the right edge of the
  9611.          virtual window.
  9612.  
  9613.          If there are no errors, VirtualReadCharacters() returns
  9614.          NO_ERROR.
  9615.  
  9616.          If there are errors, VirtualReadCharacters() returns one of
  9617.          the following:
  9618.  
  9619.          BAD_V_WINDOW if the virtual window does not exist.
  9620.  
  9621.          V_WINDOW_BOUND if the row or column specified in the virtual
  9622.          window is out of bounds.
  9623.  
  9624.  
  9625.  
  9626.  
  9627.  
  9628.          VirtualReadAttributes()
  9629.          ----------------------
  9630.  
  9631.          The VirtualReadAttributes() function reads the attributes
  9632.          from a virtual window into a buffer.  Here is the prototype.
  9633.  
  9634.          int VirtualReadAttributes(VWPOINTER w, char *buffer,
  9635.                                    unsigned row, unsigned col,
  9636.                                    unsigned length)
  9637.  
  9638.          The first argument is the virtual window.  The second
  9639.          argument is the buffer to store the attributes in.  The third
  9640.          and fourth arguments are the (row,col) position in the
  9641.          virtual window to start reading from.  The last argument is
  9642.          the number of attributes to read.  If the virtual window is
  9643.          NOATTRIBUTE, nothing is read.
  9644.  
  9645.          You must make sure that buffer has enough room to hold all of
  9646.          the attributes read in.
  9647.  
  9648.  
  9649.          Example:
  9650.  
  9651.          #include "window.h"
  9652.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9653.  
  9654.          VWPOINTER vw;
  9655.          char buf[14] = {0};      /* Null all elements of buf */
  9656.  
  9657.          main()
  9658.          {
  9659.            int i;
  9660.            WindowInitializeSystem();
  9661.            WindowSaveInitial(0);
  9662.            vw = VirtualInitialize(ATTRIBUTE,10,80,NORM);
  9663.            VirtualReadAttributes(vw,buf,1,1,13); /* Read attributes */
  9664.          }
  9665.  
  9666.  
  9667.          Page 147          The C Window Library               Page 147
  9668.  
  9669.          The example above illustrates the use of
  9670.          VirtualReadAttributes(), which reads the virtual window's
  9671.          attribute contents starting at (1,1) of the virtual window.
  9672.  
  9673.  
  9674.          If the length exceeds the right edge of the virtual window,
  9675.          VirtualReadAttributes() will read up to the right edge of the
  9676.          virtual window.
  9677.  
  9678.  
  9679.          If there are no errors, VirtualReadAttributes() returns
  9680.          NO_ERROR.
  9681.  
  9682.          If there are errors, VirtualReadAttributes() returns one of
  9683.          the following:
  9684.  
  9685.          BAD_V_WINDOW if the virtual window does not exist.
  9686.  
  9687.          V_WINDOW_BOUND if the row or column specified in the virtual
  9688.          window is out of bounds.
  9689.  
  9690.          NO_ATTRIB if the virtual window is NOATTRIBUTE.
  9691.  
  9692.  
  9693.  
  9694.  
  9695.          VirtualReadCharAndAttr()
  9696.          ------------------------
  9697.  
  9698.          The VirtualReadCharAndAttr() function reads
  9699.          character/attribute pairs from a virtual window into a
  9700.          buffer.  Here is the prototype.
  9701.  
  9702.          int VirtualReadCharAndAttr(VWPOINTER w, char *buffer,
  9703.                                     unsigned row, unsigned col,
  9704.                                     unsigned length)
  9705.  
  9706.          The first argument is the virtual window.  The second
  9707.          argument is the buffer to store the character/attribute pairs
  9708.          in.  The third and fourth arguments are the (row,col)
  9709.          position in the virtual window to start reading from.  The
  9710.          last argument is the number of character/attribute pairs to
  9711.          read.  If the window is NOATTRIBUTE, nothing is read.
  9712.  
  9713.          You must make sure that buffer has enough room to hold all of
  9714.          the character/attribute pairs read in.
  9715.  
  9716.          Example:
  9717.  
  9718.          #include "window.h"
  9719.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  9720.  
  9721.          VWPOINTER vw;
  9722.          char buf[27] = {0};      /* Null all elements of buf */
  9723.  
  9724.  
  9725.  
  9726.  
  9727.          Page 148          The C Window Library               Page 148
  9728.  
  9729.          main()
  9730.          {
  9731.            int i;
  9732.            WindowInitializeSystem();
  9733.            WindowSaveInitial(0);
  9734.            vw = VirtualInitialize(ATTRIBUTE,10,80,NORM);
  9735.            VirtualWriteString(vw,"Hello World!!",1,1);
  9736.            VirtualReadCharAndAttr(vw,buf,1,1,13);
  9737.          }
  9738.  
  9739.  
  9740.          The example above illustrates the use of
  9741.          VirtualReadCharAndAttr(), which reads the virtual window's
  9742.          character/attribute contents starting at (1,1) of the virtual
  9743.          window.  This happens to be the characters/attributes of the
  9744.          string "Hello World!!".
  9745.  
  9746.          If the length exceeds the right edge of the virtual window,
  9747.          VirtualReadCharAndAttr() will read up to the right edge of
  9748.          the virtual window.
  9749.  
  9750.  
  9751.          If there are no errors, VirtualReadCharAndAttr() returns
  9752.          NO_ERROR.
  9753.  
  9754.          If there are errors, VirtualReadCharAndAttr() returns one of
  9755.          the following:
  9756.  
  9757.          BAD_V_WINDOW if the virtual window does not exist.
  9758.  
  9759.          V_WINDOW_BOUND if the row or column specified in the virtual
  9760.          window is out of bounds.
  9761.  
  9762.          NO_ATTRIB if the virtual window is NOATTRIBUTE.
  9763.  
  9764.  
  9765.  
  9766.  
  9767.  
  9768.  
  9769.  
  9770.  
  9771.  
  9772.  
  9773.  
  9774.  
  9775.  
  9776.  
  9777.  
  9778.  
  9779.  
  9780.  
  9781.  
  9782.  
  9783.  
  9784.  
  9785.  
  9786.  
  9787.          Page 149          The C Window Library               Page 149
  9788.  
  9789.                      REPOSITIONING THE VIEWPORT
  9790.                      --------------------------
  9791.  
  9792.          A viewport can be repositioned anywhere on the virtual
  9793.          window.  This allows to view different parts of the virtual
  9794.          window.
  9795.  
  9796.  
  9797.          WindowPositionViewport()
  9798.          ------------------------
  9799.  
  9800.          The WindowPositionViewport() function positions the viewport
  9801.          to a new location on the virtual window it is associated
  9802.          with.  Here is the prototype:
  9803.  
  9804.  
  9805.          int WindowPositionViewport(WPOINTER w, unsigned row,
  9806.                                     unsigned col)
  9807.  
  9808.          The first argument is the viewport window.  The second
  9809.          argument and third arguments are is the (row,col) position of
  9810.          the virtual window associated with w.  This position will be
  9811.          where the upper left hand corner of the viewport's text area
  9812.          will be placed.
  9813.  
  9814.  
  9815.          Example:
  9816.  
  9817.          #include <stdio.h>
  9818.          #include <string.h>
  9819.          #include "window.h"
  9820.  
  9821.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  9822.  
  9823.          #define FILENAMECHARS  \
  9824.                         "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  9825.  
  9826.          VWPOINTER vw;          /* virtual window pointer */
  9827.          WPOINTER w;            /* Window pointer */
  9828.          char filename[26];
  9829.          FILE *infile;          /* input file handle */
  9830.  
  9831.          main()
  9832.          {
  9833.            unsigned int i,j,row,col;
  9834.            WindowInitializeSystem();
  9835.            WindowSaveInitial(0);
  9836.  
  9837.            /* set up a Type 0 virtual window */
  9838.            vw = VirtualInitialize(NOATTRIBUTE,200,80,0);
  9839.  
  9840.            /* set up viewport window */
  9841.            w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  9842.            WindowOpen(w);
  9843.            WindowDisplay(w,1,NOEFFECT);
  9844.  
  9845.  
  9846.  
  9847.          Page 150          The C Window Library               Page 150
  9848.  
  9849.            /* read a file name */
  9850.            read_file();
  9851.  
  9852.            /* display file in viewport */
  9853.            WindowAssignToVirtual(w,vw,1,1);
  9854.  
  9855.            row = col = 1;
  9856.            flush_keyboard_flag = TRUE; /* Set keyboard flush to TRUE */
  9857.            while (1)
  9858.            {
  9859.              switch (GET_KEY())    /* Keep getting keys until
  9860.                                       ESCAPE key is hit */
  9861.              {
  9862.                 case UARROW:      /* Move viewport up 1 line */
  9863.  
  9864.                   if (row > 1)
  9865.                     WindowPositionViewport(w,--row,col);
  9866.                 break;
  9867.                 case DARROW:      /* Move viewport down 1 line */
  9868.                   if (row < 189)
  9869.                     WindowPositionViewport(w,++row,col);
  9870.                 break;
  9871.                 case LARROW:      /* Move viewport left 1 line */
  9872.                   if (col > 1)
  9873.                     WindowPositionViewport(w,row,--col);
  9874.                 break;
  9875.                 case RARROW:      /* Move viewport right 1 line */
  9876.                   if (col < 69)
  9877.                     WindowPositionViewport(w,row,++col);
  9878.                 break;
  9879.                 case ESC:         /* End program */
  9880.                   close_all();
  9881.                 break;
  9882.              }
  9883.            }
  9884.          }
  9885.  
  9886.  
  9887.          read_file()         /* Gets a filename and displays
  9888.                                 it in the window */
  9889.          {
  9890.             int ch;
  9891.             unsigned r = 1, c = 1;
  9892.             filename[0] = 0;
  9893.             WindowWriteString(w,"Please enter a file name: ",1,1);
  9894.             WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  9895.             if ((infile = fopen(filename,"r")) == NULL)
  9896.             {
  9897.               WindowMoveCursor(w,3,1);
  9898.               WindowPrintf(w,"File name %s does not exist\n"
  9899.                              "Press a key to continue", filename);
  9900.               GET_KEY();
  9901.               close_all();
  9902.             }
  9903.             else
  9904.  
  9905.  
  9906.  
  9907.          Page 151          The C Window Library               Page 151
  9908.  
  9909.             while(1)         /* Read characters into virtual window */
  9910.             {
  9911.               ch = fgetc(infile);
  9912.               if (feof(infile))
  9913.                 break;
  9914.               if (ch != '\n')
  9915.                 VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  9916.               else
  9917.               {
  9918.                 r++;
  9919.                 c=1;
  9920.  
  9921.               }
  9922.             }
  9923.             fclose(infile);
  9924.          }
  9925.  
  9926.  
  9927.  
  9928.          close_all()
  9929.          {
  9930.            WindowClose(w,NOEFFECT);
  9931.            exit(0);
  9932.          }
  9933.  
  9934.  
  9935.          The above example reads in a text file and uses
  9936.          WindowPositionViewport() to move left, right, up, or down.
  9937.          There is no checking to see if you have scrolled past the end
  9938.          of the file.
  9939.  
  9940.          The read_file() function reads a file and copies each
  9941.          character in the file to the virtual window called vw.
  9942.  
  9943.          In the main program, the global variable flush_keyboard_flag,
  9944.          defined in the IMPORTANT GLOBAL VARIABLES section, is set to
  9945.          TRUE.  When flush_keyboard is TRUE, the keyboard buffer is
  9946.          flushed before any incoming keystrokes are accepted.
  9947.          Otherwise the keyboard buffer is not flushed.
  9948.  
  9949.          In the while(1) loop of the main program, the constants
  9950.          UARROW, DARROW, LARROW, and RARROW, stands for the up, down,
  9951.          left, and the right arrow keys on the keypad, respectively.
  9952.          The constants UARROW, DARROW, LARROW, and RARROW are defined
  9953.          in keycodes.h.  Depending on the key that is hit, the
  9954.          viewport is repositioned to point to a new row or column.
  9955.          The call to WindowPositionViewport() has three arguments.
  9956.          The first is the pointer to the viewport window, the second
  9957.          and the third are the row and the column of the virtual
  9958.          window to place the upper left hand corner of the viewport.
  9959.  
  9960.          There is minimal bounds checking in the above example,
  9961.          however you can enhance it by putting in more bounds checking
  9962.          and by implementing a page down, or page up function.
  9963.  
  9964.  
  9965.  
  9966.  
  9967.          Page 152          The C Window Library               Page 152
  9968.  
  9969.          If there are no errors, WindowPositionViewport() returns
  9970.          NO_ERROR.  If there are errors, WindowPositionViewport() will
  9971.          return one of the following values:
  9972.  
  9973.          BAD_WINDOW if the viewport window does not exist.
  9974.  
  9975.          BAD_V_WINDOW if the viewport is pointing to a virtual window
  9976.          that does not exist.
  9977.  
  9978.          V_WINDOW_BOUND if the row and col arguments are out of bounds
  9979.          of the virtual window.
  9980.  
  9981.  
  9982.  
  9983.  
  9984.  
  9985.  
  9986.  
  9987.  
  9988.  
  9989.  
  9990.  
  9991.  
  9992.  
  9993.  
  9994.  
  9995.  
  9996.  
  9997.  
  9998.  
  9999.  
  10000.  
  10001.  
  10002.  
  10003.  
  10004.  
  10005.  
  10006.  
  10007.  
  10008.  
  10009.  
  10010.  
  10011.  
  10012.  
  10013.  
  10014.  
  10015.  
  10016.  
  10017.  
  10018.  
  10019.  
  10020.  
  10021.  
  10022.  
  10023.  
  10024.  
  10025.  
  10026.  
  10027.          Page 153          The C Window Library               Page 153
  10028.  
  10029.                        SCROLLING THE VIEWPORTS
  10030.                        -----------------------
  10031.  
  10032.          Viewports can have its display scrolled left, right, up, or
  10033.          down using the WindowScrollViewport() function described
  10034.          below.
  10035.  
  10036.  
  10037.          WindowScrollViewport()
  10038.          ---------------------
  10039.  
  10040.          This functions scrolls the viewport specific number of
  10041.          characters.  Here is the prototype:
  10042.  
  10043.          int WindowScrollViewport(WPOINTER w, unsigned num,
  10044.                                   int direction)
  10045.  
  10046.          The first argument is the viewport and the second argument is
  10047.          the number of characters to scroll.  The last argument is the
  10048.          direction to scroll.  This direction can be UP, DOWN, LEFT,
  10049.          or RIGHT.
  10050.  
  10051.  
  10052.          Example:
  10053.  
  10054.  
  10055.          #include <stdio.h>
  10056.          #include <string.h>
  10057.          #include "window.h"
  10058.  
  10059.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  10060.  
  10061.          #define FILENAMECHARS  \
  10062.                     "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  10063.  
  10064.          VWPOINTER vw;          /* virtual window pointer */
  10065.          WPOINTER w;            /* Window pointer */
  10066.          char filename[26];
  10067.          FILE *infile;          /* input file handle */
  10068.  
  10069.          main()
  10070.          {
  10071.            unsigned int i,j,row,col;
  10072.            WindowInitializeSystem();
  10073.            WindowSaveInitial(0);
  10074.            /* set up a Type 0 virtual window */
  10075.            vw = VirtualInitialize(NOATTRIBUTE,200,80,0);
  10076.  
  10077.            /* set up viewport window */
  10078.            w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  10079.            WindowOpen(w);
  10080.            WindowDisplay(w,1,NOEFFECT);
  10081.            /* read a file name */
  10082.            read_file();
  10083.  
  10084.  
  10085.  
  10086.  
  10087.          Page 154          The C Window Library               Page 154
  10088.  
  10089.            /* display file in viewport */
  10090.            WindowAssignToVirtual(w,vw,1,1);
  10091.            flush_keyboard_flag = TRUE;
  10092.            while (1)
  10093.            {
  10094.              switch (GET_KEY())    /* Keep getting keys until
  10095.                                       ESCAPE key is hit */
  10096.              {
  10097.                 case UARROW:      /* Move viewport up 1 line */
  10098.                   WindowScrollViewport(w,1,UP);
  10099.                 break;
  10100.                 case DARROW:      /* Move viewport down 1 line */
  10101.                   WindowScrollViewport(w,1,DOWN);
  10102.                 break;
  10103.                 case LARROW:      /* Move viewport left 1 line */
  10104.                   WindowScrollViewport(w,1,LEFT);
  10105.                 break;
  10106.                 case RARROW:      /* Move viewport right 1 line */
  10107.                   WindowScrollViewport(w,1,RIGHT);
  10108.                 break;
  10109.                 case ESC:         /* End program */
  10110.                   close_all();
  10111.                 break;
  10112.              }
  10113.            }
  10114.          }
  10115.  
  10116.          read_file()         /* Gets a filename and
  10117.                                 displays it in the window */
  10118.          {
  10119.             int ch;
  10120.             unsigned r = 1, c = 1;
  10121.             filename[0]=0;
  10122.             WindowWriteString(w,"Please enter a file name: ",1,1);
  10123.             WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  10124.             if ((infile = fopen(filename,"r")) == NULL)
  10125.             {
  10126.               WindowMoveCursor(w,3,1);
  10127.               WindowPrintf(w,"File name %s does not exist\n"
  10128.                              "Press a key to continue", filename);
  10129.               GET_KEY();
  10130.               close_all();
  10131.             }
  10132.             else
  10133.             while(1)         /* Read characters into virtual window */
  10134.             {
  10135.               ch = fgetc(infile);
  10136.               if (feof(infile))
  10137.                 break;
  10138.               if (ch != '\n')
  10139.                 VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  10140.               else
  10141.               {
  10142.                 r++;
  10143.                 c=1;
  10144.  
  10145.  
  10146.  
  10147.          Page 155          The C Window Library               Page 155
  10148.  
  10149.               }
  10150.             }
  10151.             fclose(infile);
  10152.          }
  10153.  
  10154.  
  10155.  
  10156.          close_all()
  10157.          {
  10158.            WindowClose(w,NOEFFECT);
  10159.            exit(0);
  10160.          }
  10161.  
  10162.  
  10163.          The example above is the same as the example for the
  10164.          WindowPositionViewport() function, except that the call to
  10165.          WindowPositionViewport() is replaced with the appropriate
  10166.          WindowScrollViewport() call.
  10167.  
  10168.  
  10169.          For WindowScrollViewport(), the window is never scrolled if
  10170.          the scroll will result in the upper left hand corner of the
  10171.          viewport being out of bounds of the virtual window.  For
  10172.          example, you cannot scroll left 1 character if the viewport
  10173.          is located at (1,1) of the virtual window, similarly you
  10174.          cannot scroll right if the virtual window has a maximum of 80
  10175.          characters and the upper left hand corner of the viewport is
  10176.          situated at (1,80).  The same restrictions apply for
  10177.          scrolling up and down.
  10178.  
  10179.          If there are no errors, all of the WindowScrollViewport()
  10180.          functions will return NO_ERROR.
  10181.  
  10182.          If there are errors, these functions will return the
  10183.          following value:
  10184.  
  10185.          V_WINDOW_BOUND if the scroll will cause the upper left hand
  10186.          position of the viewport to be out of bounds.
  10187.  
  10188.  
  10189.  
  10190.  
  10191.  
  10192.  
  10193.  
  10194.  
  10195.  
  10196.  
  10197.  
  10198.  
  10199.  
  10200.  
  10201.  
  10202.  
  10203.  
  10204.  
  10205.  
  10206.  
  10207.          Page 156          The C Window Library               Page 156
  10208.  
  10209.               WRITING VIRTUAL WINDOW CONTENTS TO A FILE
  10210.               -----------------------------------------
  10211.  
  10212.          The C Window Library allows you to print the contents of a
  10213.          virtual window using the VirtualWriteTextToFile() function.
  10214.  
  10215.  
  10216.          VirtualWriteTextToFile()
  10217.          ------------------------
  10218.  
  10219.          The VirtualWriteTextToFile() function allows you to print the
  10220.          contents of a virtual window to a file.  Here is the
  10221.          prototype:
  10222.  
  10223.          int VirtualWriteTextToFile(VWPOINTER vw, char *filename,
  10224.                                     int mode)
  10225.  
  10226.  
  10227.          The first argument is the virtual window.  The second
  10228.          argument is the file name.  This file can be any of the DOS
  10229.          filenames ("con", "prn", "aux", etc.).  The file specified by
  10230.          filename must be closed before calling
  10231.          VirtualWriteTextToFile(), and the file handle is
  10232.          automatically closed before exiting VirtualWriteTextToFile().
  10233.  
  10234.          The last argument is the mode switch.  If mode is 1, a
  10235.          newline ('\n') is written to the file after each line of the
  10236.          virtual window written to the file.  If mode is 0, no newline
  10237.          character is written.  When mode 0 is chosen, the file is
  10238.          open in binary mode, else it is open in text mode.
  10239.  
  10240.          Example:
  10241.  
  10242.          #include "window.h"
  10243.  
  10244.          VWPOINTER vw;
  10245.          char *filename = "wintext";
  10246.          char *filename2 = "wintext2";
  10247.  
  10248.          main()
  10249.          {
  10250.            int i;
  10251.            WindowInitializeSystem();
  10252.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  10253.            for (i=1;i<=10;i++)
  10254.              VirtualWriteString(vw,"Hello World!!",i,1);
  10255.            VirtualWriteTextToFile(vw,filename,1);  /* use newlines */
  10256.            VirtualWriteTextToFile(vw,filename2,0); /* no newlines */
  10257.          }
  10258.  
  10259.          The example above illustrates two calls to
  10260.          VirtualWriteTextToFile().  The first call writes the contents
  10261.          of the virtual window vw to a file called "wintext".  Note
  10262.          that the mode parameter for the first call is 1.  This will
  10263.          cause '\n' to be written to the file for each line of the
  10264.  
  10265.  
  10266.  
  10267.          Page 157          The C Window Library               Page 157
  10268.  
  10269.          virtual window.  The second call writes the virtual window
  10270.          text to a file call "wintest2", with the mode parameter being
  10271.          0 (no '\n').
  10272.  
  10273.          Please note that VirtualWriteTextToFile() does not check if
  10274.          the file already exists, so be careful that you do not
  10275.          replace files that are important to you.
  10276.  
  10277.          If there are no errors, VirtualWriteTextToFile() returns
  10278.          NO_ERROR.
  10279.  
  10280.          If there are errors, VirtualWriteTextToFile() will return one
  10281.          of the following:
  10282.  
  10283.  
  10284.          BAD_V_WINDOW if the virtual window does not exist.
  10285.  
  10286.          FILE_CANT_OPEN if the file specified by filename cannot be
  10287.          open.
  10288.  
  10289.          FILE_CANT_CLOSE if the file specified by filename cannot be
  10290.          closed.
  10291.  
  10292.  
  10293.  
  10294.  
  10295.  
  10296.  
  10297.  
  10298.  
  10299.  
  10300.  
  10301.  
  10302.  
  10303.  
  10304.  
  10305.  
  10306.  
  10307.  
  10308.  
  10309.  
  10310.  
  10311.  
  10312.  
  10313.  
  10314.  
  10315.  
  10316.  
  10317.  
  10318.  
  10319.  
  10320.  
  10321.  
  10322.  
  10323.  
  10324.  
  10325.  
  10326.  
  10327.          Page 158          The C Window Library               Page 158
  10328.  
  10329.                       MOVING THE LOGICAL CURSOR
  10330.                       -------------------------
  10331.  
  10332.          You can move and get the position of the logical cursor in a
  10333.          virtual window.
  10334.  
  10335.  
  10336.  
  10337.          VirtualMoveCursor()
  10338.          -------------------
  10339.  
  10340.          The VirtualMoveCursor() function moves a virtual window's
  10341.          logical cursor to a new location.  Here is the prototype:
  10342.  
  10343.          int VirtualMoveCursor(VWPOINTER vw, unsigned row,
  10344.                                unsigned col)
  10345.  
  10346.          The first argument is the virtual window, and the second and
  10347.          third arguments denote the new (row,col) position of the
  10348.          logical cursor.
  10349.  
  10350.          Example:
  10351.  
  10352.          #include "window.h"
  10353.  
  10354.  
  10355.          VWPOINTER vw;
  10356.  
  10357.          main()
  10358.          {
  10359.            int i;
  10360.            WindowInitializeSystem();
  10361.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  10362.            VirtualMoveCursor(vw,10,10)   /* Moves the logical cursor
  10363.                                             to row 10, column 10 of
  10364.                                             the virtual window */
  10365.          }
  10366.  
  10367.          If there are no errors, VirtualMoveCursor() returns NO_ERROR.
  10368.          If there are errors, VirtualMoveCursor() returns one of the
  10369.          following values:
  10370.  
  10371.          BAD_V_WINDOW if the virtual window does not exist.
  10372.  
  10373.          V_WINDOW_BOUND if either the row or column specified is out
  10374.          of bounds.
  10375.  
  10376.  
  10377.  
  10378.  
  10379.          VirtualGetCursorPosition()
  10380.          --------------------------
  10381.  
  10382.          The VirtualGetCursorPosition() function gives the current row
  10383.          and column of the cursor in a virtual window.  Here is the
  10384.          prototype:
  10385.  
  10386.  
  10387.          Page 159          The C Window Library               Page 159
  10388.  
  10389.          int VirtualGetCursorPosition(VWPOINTER vw, unsigned *row,
  10390.                                       unsigned *col)
  10391.  
  10392.          The row and col arguments are pointers to unsigned integers
  10393.          that will contain the row and column of the cursor after
  10394.          VirtualGetCursorPosition() is called.
  10395.  
  10396.          Example:
  10397.  
  10398.          #include "window.h"
  10399.  
  10400.          VWPOINTER vw;
  10401.  
  10402.          main()
  10403.          {
  10404.            unsigned row,col;
  10405.            WindowInitializeSystem();
  10406.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  10407.            VirtualMoveCursor(vw,7,4);
  10408.            VirtualGetCursorPosition(vw,&row,&col);
  10409.          }
  10410.  
  10411.          If there are no errors, VirtualGetCursorPosition() returns
  10412.          NO_ERROR.
  10413.  
  10414.          If there are errors, VirtualGetCursorPosition() returns the
  10415.          following value:
  10416.  
  10417.          BAD_V_WINDOW if the window does not exist.
  10418.  
  10419.  
  10420.  
  10421.  
  10422.  
  10423.  
  10424.  
  10425.  
  10426.  
  10427.  
  10428.  
  10429.  
  10430.  
  10431.  
  10432.  
  10433.  
  10434.  
  10435.  
  10436.  
  10437.  
  10438.  
  10439.  
  10440.  
  10441.  
  10442.  
  10443.  
  10444.  
  10445.  
  10446.  
  10447.          Page 160          The C Window Library               Page 160
  10448.  
  10449.                       CLEARING VIRTUAL WINDOWS
  10450.                       ------------------------
  10451.  
  10452.  
  10453.          The C Window Library contains functions that clears the
  10454.          entire virtual window, or clears defined rectangular regions
  10455.          of the virtual window.
  10456.  
  10457.  
  10458.          VirtualClear()
  10459.          --------------
  10460.  
  10461.          The VirtualClear() function clears an entire virtual window
  10462.          to spaces.  Here is the prototype:
  10463.  
  10464.                    int VirtualClear(VWPOINTER vw)
  10465.  
  10466.          The only argument is the virtual window to clear.
  10467.  
  10468.          Example:
  10469.  
  10470.          #include "window.h"
  10471.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  10472.  
  10473.          VWPOINTER vw;
  10474.          WPOINTER w;
  10475.  
  10476.          main()
  10477.          {
  10478.            int i;
  10479.            WindowInitializeSystem();
  10480.            WindowSaveInitial(0);
  10481.            w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  10482.            vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  10483.            WindowOpen(w);
  10484.            WindowDisplay(w,1,NOEFFECT);
  10485.            WindowAssignToVirtual(w,vw,1,1);
  10486.            for (i=1;i<=10;i++)
  10487.              VirtualWriteString(vw,"Hello World!!",i,1);
  10488.            GET_KEY();
  10489.            VirtualClear(vw);
  10490.          }
  10491.  
  10492.          If there is no error, VirtualClear() returns NO_ERROR.
  10493.  
  10494.          If there is an error, VirtualClear() returns the following
  10495.          values:
  10496.  
  10497.          BAD_V_WINDOW if the virtual window does not exist.
  10498.  
  10499.  
  10500.  
  10501.  
  10502.  
  10503.  
  10504.  
  10505.  
  10506.  
  10507.          Page 161          The C Window Library               Page 161
  10508.  
  10509.          VirtualClearAttr()
  10510.          ------------------
  10511.  
  10512.          The VirtualClearAttr() function works the same way as the
  10513.          VirtualClear() function except that an attribute is
  10514.          specified.  Here is the prototype:
  10515.  
  10516.                 int VirtualClearAttr(VWPOINTER vw, int attr)
  10517.  
  10518.          The second argument is the video attribute to use.  If the
  10519.          virtual window is NOATTRIBUTE, this function only clears the
  10520.          text.
  10521.  
  10522.          Example:
  10523.  
  10524.          #include "window.h"
  10525.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  10526.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  10527.          WPOINTER w;
  10528.          VWPOINTER vw;
  10529.  
  10530.          main()
  10531.          {
  10532.            int i;
  10533.            WindowInitializeSystem();
  10534.            WindowSaveInitial(0);
  10535.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  10536.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  10537.            WindowOpen(w);
  10538.            WindowDisplay(w,1,NOEFFECT);
  10539.            WindowAssignToVirtual(w,vw,1,1);
  10540.            for (i=1;i<=10;i++)
  10541.              VirtualWriteString(vw,"Hello World!!",i,1);
  10542.            GET_KEY();
  10543.            VirtualClearAttr(vw,REVERSE);
  10544.          }
  10545.  
  10546.          The return values for VirtualClearAttr() are the same as
  10547.          VirtualClear(), except for the following error:
  10548.  
  10549.          NO_ATTRIB if the virtual window is NOATTRIBUTE.
  10550.  
  10551.  
  10552.          VirtualClearRegion()
  10553.          -------------------
  10554.  
  10555.          The VirtualClearRegion() function clears a region of a
  10556.          virtual window.  To use the VirtualClearRegion() function,
  10557.          you must describe the rectangular region to clear.  Here is
  10558.          the prototype:
  10559.  
  10560.          int VirtualClearRegion(VWPOINTER vw, unsigned urow,
  10561.                                 unsigned ucol, unsigned lrow,
  10562.                                 unsigned lcol)
  10563.  
  10564.  
  10565.  
  10566.  
  10567.          Page 162          The C Window Library               Page 162
  10568.  
  10569.          where (urow,ucol) describes the upper left of the rectangle
  10570.          and (lrow,lcol) is the lower right of the virtual window.
  10571.  
  10572.  
  10573.          Example:
  10574.  
  10575.          #include "window.h"
  10576.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  10577.          WPOINTER w;
  10578.          VWPOINTER vw;
  10579.  
  10580.          main()
  10581.          {
  10582.            int i;
  10583.            WindowInitializeSystem();
  10584.            WindowSaveInitial(0);
  10585.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  10586.            vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  10587.            WindowOpen(w);
  10588.            WindowDisplay(w,1,NOEFFECT);
  10589.            WindowAssignToVirtual(w,vw,1,1);
  10590.            for (i=1;i<=10;i++)
  10591.              VirtualWriteString(vw,"Hello World!!",i,1);
  10592.            GET_KEY();
  10593.            VirtualClearRegion(vw,4,4,8,15);
  10594.          }
  10595.  
  10596.  
  10597.          The VirtualClearRegion() call will clear the region described
  10598.          by the rectangular coordinates (4,4) and (8,15).
  10599.  
  10600.          If there is no error, VirtualClearRegion() returns NO_ERROR.
  10601.  
  10602.          If there is an error, the VirtualClearRegion() function will
  10603.          return the following values:
  10604.  
  10605.          BAD_V_WINDOW if the VWPOINTER vw does not exist.
  10606.  
  10607.          V_WINDOW_BOUND if the rectangular region defined is out of
  10608.          bounds of the virtual window.
  10609.  
  10610.  
  10611.  
  10612.  
  10613.          VirtualClearRegionAttr()
  10614.          ------------------------
  10615.  
  10616.          The VirtualClearRegionAttr() function works the same as the
  10617.          VirtualClearRegion() function, except that a video attribute
  10618.          is specified.  Here is the prototype:
  10619.  
  10620.          int VirtualClearRegionAttr(VWPOINTER vw, unsigned urow,
  10621.                                     unsigned ucol, unsigned lrow,
  10622.                                     unsigned lcol, int attr)
  10623.  
  10624.  
  10625.  
  10626.  
  10627.          Page 163          The C Window Library               Page 163
  10628.  
  10629.          The attr argument is a video attribute to use to clear the
  10630.          region.  If the virtual window is NOATTRIBUTE, the attribute
  10631.          argument is ignored.
  10632.  
  10633.  
  10634.          Example:
  10635.  
  10636.          #include "window.h"
  10637.          #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  10638.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  10639.          WPOINTER w;
  10640.          VWPOINTER vw;
  10641.  
  10642.          main()
  10643.          {
  10644.            int i;
  10645.            WindowInitializeSystem();
  10646.            WindowSaveInitial(0);
  10647.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  10648.            vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  10649.            WindowOpen(w);
  10650.            WindowDisplay(w,1,NOEFFECT);
  10651.            WindowAssignToVirtual(w,vw,1,1);
  10652.            for (i=1;i<=10;i++)
  10653.              VirtualWriteString(vw,"Hello World!!",i,1);
  10654.            GET_KEY();
  10655.            VirtualClearRegionAttr(vw,4,4,8,15,REVERSE);
  10656.          }
  10657.  
  10658.  
  10659.          The VirtualClearRegionAttr() call will clear the region
  10660.          described by the rectangular coordinates (4,4) and (8,15)
  10661.          using the video attribute defined by the constant REVERSE.
  10662.  
  10663.          The VirtualClearRegionAttr() returns the same values as
  10664.          VirtualClearRegion() with an additional error condition:
  10665.  
  10666.          NO_ATTRIB if the virtual window is NOATTRIBUTE.
  10667.  
  10668.  
  10669.  
  10670.  
  10671.  
  10672.  
  10673.  
  10674.  
  10675.  
  10676.  
  10677.  
  10678.  
  10679.  
  10680.  
  10681.  
  10682.  
  10683.  
  10684.  
  10685.  
  10686.  
  10687.          Page 164          The C Window Library               Page 164
  10688.  
  10689.                          FREEZING VIEWPORTS
  10690.                          ------------------
  10691.  
  10692.  
  10693.          You can temporarily suspend or 'freeze' a viewport window
  10694.          from displaying updates to the virtual window.  This is good
  10695.          if there is data being written to the virtual window which
  10696.          takes a long time to generate.  The viewport can be frozen
  10697.          when the information is being written, and unfrozen when the
  10698.          writing of the data is terminated.
  10699.  
  10700.  
  10701.          WindowFreeze()
  10702.          --------------
  10703.  
  10704.          The WindowFreeze() function suspends or resumes displaying of
  10705.          virtual window updates on a viewport window.  Here is the
  10706.          prototype:
  10707.  
  10708.               int WindowFreeze(WPOINTER w, int option)
  10709.  
  10710.          The first argument is the viewport window, and the second
  10711.          argument is the option flag.  If this flag is 0, the window
  10712.          is unfrozen, i.e. the window will display virtual window
  10713.          updates.  If it is 1, the window will suspend virtual window
  10714.          updates from being displayed.
  10715.  
  10716.          Example:
  10717.  
  10718.          #include "window.h"
  10719.  
  10720.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  10721.  
  10722.          VWPOINTER vw;
  10723.          WPOINTER w;
  10724.  
  10725.          main()
  10726.          {
  10727.            int i;
  10728.            WindowInitializeSystem();
  10729.            WindowSaveInitial(0);
  10730.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  10731.            vw = VirtualInitialize(NOATTRIBUTE,10,80,NORM);
  10732.            WindowOpen(w);
  10733.            WindowAssignToVirtual(w,vw,1,1);
  10734.            WindowDisplay(w,1,NOEFFECT);
  10735.            /* Freeze Viewport */
  10736.            WindowFreeze(w,1);
  10737.            for (i=1;i<=10;i++)
  10738.            {
  10739.              delay(1000);
  10740.              VirtualPrintf(vw,"Line %d\n",i);
  10741.            }
  10742.            /* Unfreeze window */
  10743.            WindowFreeze(w,0);
  10744.  
  10745.  
  10746.  
  10747.          Page 165          The C Window Library               Page 165
  10748.  
  10749.            GET_KEY();
  10750.  
  10751.            /* Now try with window always displaying data */
  10752.            VirtualClear(vw);
  10753.            for (i=1;i<=10;i++)
  10754.            {
  10755.              delay(1000);
  10756.              VirtualPrintf(vw,"Line %d\n",i);
  10757.            }
  10758.          }
  10759.  
  10760.  
  10761.  
  10762.          The above program first freezes the viewport w with the first
  10763.          call to WindowFreeze().  Then text is written slowly to the
  10764.          virtual window vw.  This text is not displayed until the
  10765.          window is unfrozen again with the second call to
  10766.          WindowFreeze().  Everything is reset and the writing of the
  10767.          text to the virtual window is done again, but this time the
  10768.          viewport is always displaying virtual window updates, even
  10769.          when the text is being written to the virtual window.
  10770.  
  10771.          The delay() function is discussed in the TIMED DELAYS
  10772.          section.
  10773.  
  10774.  
  10775.          If there is no error WindowFreeze() returns NO_ERROR.
  10776.  
  10777.          If there are errors, WindowFreeze() returns one of the
  10778.          following values:
  10779.  
  10780.          BAD_WINDOW if the viewport window does not exist.
  10781.  
  10782.          BAD_V_WINDOW if the virtual window that the viewport is
  10783.          displaying does not exist.
  10784.  
  10785.  
  10786.  
  10787.  
  10788.  
  10789.  
  10790.  
  10791.  
  10792.  
  10793.  
  10794.  
  10795.  
  10796.  
  10797.  
  10798.  
  10799.  
  10800.  
  10801.  
  10802.  
  10803.  
  10804.  
  10805.  
  10806.  
  10807.          Page 166          The C Window Library               Page 166
  10808.  
  10809.                     DISPOSING OF VIRTUAL WINDOWS
  10810.                     ----------------------------
  10811.  
  10812.  
  10813.          The last step is to dispose of the virtual window.  The
  10814.          function to do this is the VirtualFree() function.
  10815.  
  10816.  
  10817.          VirtualFree()
  10818.          -------------
  10819.  
  10820.          The VirtualFree() function frees all the memory allocated to
  10821.          the virtual window and destroys the virtual window pointer.
  10822.          Here is the prototype:
  10823.  
  10824.          int VirtualFree(VWPOINTER vw, int hideflag, int effect)
  10825.  
  10826.          The first argument is the virtual window.  The second
  10827.          argument is a flag that determines whether any viewports
  10828.          displaying the virtual window should be hidden.  If this
  10829.          argument is 1, all viewports displaying the virtual window is
  10830.          hidden.  If the argument is 0, all viewports are cleared, but
  10831.          not hidden.  The third argument is the special effect to use
  10832.          when hiding the viewports.  This argument is ignored if
  10833.          hideflag is 0.  For a list of special effects, refer to the
  10834.          DISPLAYING WINDOWS section.
  10835.  
  10836.          Once VirtualFree() is called you must not use the VWPOINTER
  10837.          again unless you assign it to another virtual window, or
  10838.          create a new virtual window.
  10839.  
  10840.          Example:
  10841.  
  10842.          #include "window.h"
  10843.  
  10844.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  10845.          VWPOINTER vw;          /* virtual window pointer */
  10846.          WPOINTER w1, w2;
  10847.          main()
  10848.          {
  10849.            WindowInitializeSystem();
  10850.            WindowSaveInitial(0);
  10851.            vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  10852.            w1 = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,
  10853.                                  SINGLEBOX);
  10854.            w2 = WindowInitialize(BORDER,13,1,20,10,NORM,NORM,
  10855.                                  DOUBLEBOX);
  10856.            WindowOpen(w1);
  10857.            WindowOpen(w2);
  10858.            WindowDisplay(w1,1,NOEFFECT);
  10859.            WindowDisplay(w2,2,NOEFFECT);
  10860.            VirtualWriteString(vw,"This is a string",1,1);
  10861.  
  10862.            WindowAssignToVirtual(w1,vw,1,1);
  10863.            WindowAssignToVirtual(w2,vw,1,1);
  10864.  
  10865.  
  10866.  
  10867.          Page 167          The C Window Library               Page 167
  10868.  
  10869.            GET_KEY();
  10870.            VirtualFree(vw,1,NOEFFECT);
  10871.          }
  10872.  
  10873.           If there are no errors, VirtualFree() returns NO_ERROR.
  10874.  
  10875.           If there are errors, VirtualFree() returns the following
  10876.           value:
  10877.  
  10878.           BAD_V_WINDOW if the virtual window does not exist.
  10879.  
  10880.  
  10881.  
  10882.  
  10883.  
  10884.  
  10885.  
  10886.  
  10887.  
  10888.  
  10889.  
  10890.  
  10891.  
  10892.  
  10893.  
  10894.  
  10895.  
  10896.  
  10897.  
  10898.  
  10899.  
  10900.  
  10901.  
  10902.  
  10903.  
  10904.  
  10905.  
  10906.  
  10907.  
  10908.  
  10909.  
  10910.  
  10911.  
  10912.  
  10913.  
  10914.  
  10915.  
  10916.  
  10917.  
  10918.  
  10919.  
  10920.  
  10921.  
  10922.  
  10923.  
  10924.  
  10925.  
  10926.  
  10927.          Page 168          The C Window Library               Page 168
  10928.  
  10929.                      INTRODUCTION TO MENU SYSTEM
  10930.                      ---------------------------
  10931.  
  10932.          Menu systems are important entities in any program.  The C
  10933.          Window Library has functions that create popup, pull-down,
  10934.          and bar menus.  The popup menus are scrollable menus with a
  10935.          limit of 65,535 selections.  The bar menus can have any
  10936.          number of entries.  As of this version, the bar menus are not
  10937.          scrollable, although there will be an implementation of
  10938.          scrolling bar menus in a future version.  The pull-down menus
  10939.          are a combination of popup and bar menus.  You can change
  10940.          entries, hide entries, use hotkeys to invoke a menu entry,
  10941.          and many more things.
  10942.  
  10943.  
  10944.          Menu Manager
  10945.          ------------
  10946.  
  10947.          The menu manager is the code in The C Window Library that
  10948.          handles moving the highlight bar in the menu, calling the
  10949.          menu functions when they are selected, keeps tracks of
  10950.          available entries, and other functions that keep track of the
  10951.          menu when selections are made.
  10952.  
  10953.  
  10954.  
  10955.          Necessary "include" files
  10956.          -------------------------
  10957.  
  10958.          To use the menu system in your program, you must include the
  10959.          "menu.h" file supplied.  This file automatically includes the
  10960.          "window.h" file, therefore you do not have to include
  10961.          "window.h" when you use "menu.h".
  10962.  
  10963.  
  10964.  
  10965.  
  10966.  
  10967.  
  10968.  
  10969.  
  10970.  
  10971.  
  10972.  
  10973.  
  10974.  
  10975.  
  10976.  
  10977.  
  10978.  
  10979.  
  10980.  
  10981.  
  10982.  
  10983.  
  10984.  
  10985.  
  10986.  
  10987.          Page 169          The C Window Library               Page 169
  10988.  
  10989.                             POP-UP MENUS
  10990.                             ------------
  10991.  
  10992.  
  10993.          Description
  10994.          -----------
  10995.  
  10996.          A popup menu is a vertical menu with a list of entries that
  10997.          are selected by placing a highlight bar on the entry and
  10998.          pressing return, or by invoking the function by using a
  10999.          hotkey.  Pop-up menus can be scrollable, in other words, if
  11000.          there are more entries than can be displayed in the window,
  11001.          the menu will scroll through the rest of the selections.  You
  11002.          can have up to 65,535 selections in the popup menu.
  11003.  
  11004.          Here is a partial list of the various options you can have
  11005.          with popup menus:
  11006.  
  11007.             * Highlight bar wrapping - wrap highlight bar to first or
  11008.                                        last option when there are no
  11009.                                        more selections.
  11010.  
  11011.             * Static Menus - menu remains on the screen when entry is
  11012.                              selected.
  11013.  
  11014.             * Perpetual Menus - menu remain on the screen regardless
  11015.               of whether the PopupSelectMenu() function (explained
  11016.               later) is called or not.
  11017.  
  11018.             * Hidden (Unavailable) entries - You can make an entry in
  11019.                                              the popup menu
  11020.                                              unavailable or available
  11021.                                              at any time.
  11022.  
  11023.             * Color scheme of the menu - You can customize the color
  11024.                                          of the highlight bar, the
  11025.                                          hotkey letters, hidden
  11026.                                          entries, etc.
  11027.  
  11028.             * Change entry names   - You can safely change the names
  11029.                                       displayed in the menu at any
  11030.                                       time.
  11031.  
  11032.             * Use a mouse to select menu entries.
  11033.  
  11034.  
  11035.  
  11036.  
  11037.          Windows and Virtual Windows
  11038.          ---------------------------
  11039.  
  11040.          Pop-up menus use virtual windows to write menu selections,
  11041.          and use normal windows to display the selections.  This
  11042.          method of using virtual windows enables the menu manager to
  11043.          scroll through the menu selections if the window is not tall
  11044.          enough to display all of the selections.
  11045.  
  11046.  
  11047.          Page 170          The C Window Library               Page 170
  11048.  
  11049.                         CREATING POP-UP MENUS
  11050.                         ---------------------
  11051.  
  11052.  
  11053.          The POPUP_MENU_ENTRY structure
  11054.          ------------------------------
  11055.  
  11056.          The two most important parts of the popup menu are the
  11057.          POPUP_MENU_ENTRY structure and the POPUP_MENU_PTR structure.
  11058.          The POPUP_MENU_ENTRY structure is the first step in creating
  11059.          a popup menu and is discussed here.
  11060.  
  11061.          Each entry in the popup menu has its own POPUP_MENU_ENTRY
  11062.          structure associated with it.  The layout of this structure
  11063.          is as follows:
  11064.  
  11065.  
  11066.  
  11067.          char     *entry_name    -- This is the string that is
  11068.                                      displayed in the popup virtual
  11069.                                      window.
  11070.  
  11071.          unsigned  row            -- Row in the virtual window to
  11072.                                      display entry_name.
  11073.  
  11074.          char      hotkey_letter  -- This is a character in entry_name
  11075.                                      that is highlighted from the rest
  11076.                                      of the characters in entry_name.
  11077.                                      This letter will automatically
  11078.                                      invoke the menu function
  11079.                                      associated with entry_name.
  11080.  
  11081.          unsigned  ext_hotkey     -- This is a secondary hotkey.  The
  11082.                                      difference between hotkey_letter
  11083.                                      and ext_hotkey is that ext_hotkey
  11084.                                      can handle keys that are not
  11085.                                      ASCII keys (the F keys, Alt and
  11086.                                      Ctrl key combinations, etc.).
  11087.  
  11088.          int (*func)()            -- Pointer to function that is
  11089.                                      invoked when option is selected.
  11090.  
  11091.          An array of POPUP_MENU_ENTRY's are needed to create all of
  11092.          the entries on the popup menu.  The order of the array
  11093.          elements determine the order of how they are placed in the
  11094.          virtual window.  A code sample to create an array of
  11095.          POPUP_MENU_ENTRY's would be as follows:
  11096.  
  11097.          #include "menu.h"
  11098.          int menu_func();
  11099.  
  11100.          POPUP_MENU_ENTRY menu_items[] = {
  11101.                               " Load      F3", /* entry name */
  11102.                                 1,             /* row number */
  11103.                                'L',            /* hotkey */
  11104.  
  11105.  
  11106.  
  11107.          Page 171          The C Window Library               Page 171
  11108.  
  11109.                                 F3,            /* secondary hotkey */
  11110.                                 menu_func,     /* function to call if
  11111.                                                   chosen */
  11112.  
  11113.                              /* now do rest of the popup entries */
  11114.  
  11115.                               " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  11116.                               " New"         ,3, 'N',0,menu_func,
  11117.                               " Save      F2",4, 'S',F2,menu_func,
  11118.                               " Write to    ",5, 'W',0,menu_func,
  11119.                               " Directory   ",6, 'D',0,menu_func,
  11120.                               " Change Dir"  ,7, 'C',0,menu_func,
  11121.                               " OS shell"    ,8, 'O',0,menu_func,
  11122.                               " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  11123.  
  11124.                              /* Terminate with a CWL_NULL and 0 */
  11125.                               CWL_NULL,0};
  11126.  
  11127.  
  11128.          The first include file, menu.h, is must be included in each
  11129.          source file that calls menu functions.
  11130.  
  11131.          As you can see, there is an array of POPUP_MENU_ENTRY's,
  11132.          namely menu_items.  Each entry consists of an entry name, row
  11133.          number, hotkey letter, secondary hotkey, and a function to
  11134.          call when the entry is selected.  The list of
  11135.          POPUP_MENU_ENTRY's MUST be terminated by a CWL_NULL entry
  11136.          name, and a row number of 0. If this rule is violated, the
  11137.          menu manager will not know where the last entry is, and will
  11138.          cause chaos when the program is run.
  11139.  
  11140.          There is an alternate method of creating the array of
  11141.          POPUP_MENU_ENTRY's.  Later on we will discuss creating these
  11142.          entries dynamically.
  11143.  
  11144.  
  11145.  
  11146.          Defining Hotkeys
  11147.          ----------------
  11148.  
  11149.          The hotkey_letter defined in the POPUP_MENU_ENTRY structure
  11150.          must match one of the letters in its corresponding
  11151.          entry_name.  For example, " Load     F3", has the
  11152.          hotkey_letter defined as 'L'.  Since 'L' matches the first
  11153.          letter in " Load     F3",  the first 'L' in " Load     F3" is
  11154.          highlighted.  If there is no match, or if the hotkey_letter
  11155.          is 0, there is no hotkey associated with this option.  When
  11156.          the menu is displayed, either the 'l' or 'L' will be accepted
  11157.          as a valid selection to the entry " Load     F3".   If there
  11158.          is a POPUP_MENU_ENTRY with the same hotkey letter as another
  11159.          POPUP_MENU_ENTRY, the POPUP_MENU_ENTRY closest to the first
  11160.          entry is chosen.
  11161.  
  11162.  
  11163.  
  11164.  
  11165.  
  11166.  
  11167.          Page 172          The C Window Library               Page 172
  11168.  
  11169.          The ext_hotkey is used if the hotkey cannot be defined as a
  11170.          single character, or if you want another hotkey definition.
  11171.          In the above example, the " Load     F3" entry_name has an
  11172.          ext_hotkey of F3 (defined in keycodes.h).  If the F3 key is
  11173.          pressed, the function menu_func() is automatically invoked.
  11174.          If the ext_hotkey letter is 0, there is no ext_hotkey
  11175.          defined.  If there is a POPUP_MENU_ENTRY with the same
  11176.          ext_hotkey as another POPUP_MENU_ENTRY, the POPUP_MENU_ENTRY
  11177.          closest to the first entry is chosen.
  11178.  
  11179.  
  11180.  
  11181.          Assigning the function to perform
  11182.          ---------------------------------
  11183.  
  11184.          The func() member is the function that is performed when its
  11185.          corresponding entry_name is chosen.
  11186.  
  11187.  
  11188.          This is the first step in completing the total popup menu.
  11189.          Once the array of POPUP_MENU_ENTRY's is created the next step
  11190.          is to define the colors for each element of the popup menu.
  11191.  
  11192.  
  11193.  
  11194.          Coloring Popup Menus
  11195.          --------------------
  11196.  
  11197.          An array of unsigned integers is used to define the color
  11198.          scheme of the popup menu.  Each element of this array stands
  11199.          for a certain area of the popup menu.  Here is a list of
  11200.          array positions and what they stand for.
  11201.  
  11202.          Position
  11203.          Constant
  11204.          --------
  11205.  
  11206.          ENTRYCOLOR    --  color of the text area of the viewport
  11207.                            window.
  11208.  
  11209.          BORDERCOLOR    --  color of the border of the viewport window.
  11210.  
  11211.          HOTKEYCOLOR    --  color of the hotkey letter.
  11212.  
  11213.          HIGHLIGHTCOLOR --  color of the highlight bar.
  11214.  
  11215.          UNAVAILCOLOR   --  color of the unavailable entries.
  11216.  
  11217.          Position ENTRYCOLOR of the array defines the color of the
  11218.          text area of the viewport window.  This in turn defines the
  11219.          color of each entry_name of all of the POPUP_MENU_ENTRY's.
  11220.  
  11221.          Position BORDERCOLOR defines the color of the border of the
  11222.          viewport window.  As was stated above, the menu is written to
  11223.          a virtual window, and a viewport is used to display the menu
  11224.  
  11225.  
  11226.  
  11227.          Page 173          The C Window Library               Page 173
  11228.  
  11229.          entries.  If the viewport window does not have a border, this
  11230.          attribute is ignored.
  11231.  
  11232.          Position HOTKEYCOLOR defines the color to use for the hotkey
  11233.          letter.  In the above example, the 'L', 'P', 'N', etc. of
  11234.          each respective entry_name is displayed using this color.
  11235.  
  11236.          Position HIGHLIGHTCOLOR defines the color used for the
  11237.          highlight bar.  This bar is moved up and down when the user
  11238.          is making a selection.
  11239.  
  11240.          Position UNAVAILCOLOR defines the color of the unavailable
  11241.          menu entries.  Whenever a menu entry is unavailable, the
  11242.          entry_name string displayed takes on this color.
  11243.  
  11244.          Colors can be created by using the CREATE_VIDEO_ATTRIBUTE().
  11245.          A code sample to create the colors is as follows:
  11246.  
  11247.  
  11248.          #include "menu.h"
  11249.          unsigned int menu_colors[5];
  11250.  
  11251.          main()
  11252.          {
  11253.            {... code ...}
  11254.            menu_colors[ENTRYCOLOR] =
  11255.                       CREATE_VIDEO_ATTRIBUTE(black,white);
  11256.            menu_colors[BORDERCOLOR] =
  11257.                       CREATE_VIDEO_ATTRIBUTE(black,white);
  11258.            menu_colors[HOTKEYCOLOR] =
  11259.                       CREATE_VIDEO_ATTRIBUTE(blue,white);
  11260.            menu_colors[HIGHLIGHTCOLOR] =
  11261.                       CREATE_VIDEO_ATTRIBUTE(black,cyan);
  11262.            menu_colors[UNAVAILCOLOR] =
  11263.                       CREATE_VIDEO_ATTRIBUTE(white,black);
  11264.              /* rest of the program */
  11265.          }
  11266.  
  11267.  
  11268.  
  11269.  
  11270.          Creating popup menu entries dynamically
  11271.          ---------------------------------------
  11272.  
  11273.          You can create POPUP_MENU_ENTRY's dynamically, instead of
  11274.          defining a pre-determined array of POPUP_MENU_ENTRY's
  11275.          explained previously.  Here is an example:
  11276.  
  11277.          Usual method:
  11278.          ------------
  11279.  
  11280.          POPUP_MENU_ENTRY menu_items[] = {
  11281.                          " Load      F3", /* entry name */
  11282.                            1,             /* row number */
  11283.                           'L',            /* hotkey */
  11284.  
  11285.  
  11286.  
  11287.          Page 174          The C Window Library               Page 174
  11288.  
  11289.                            F3,            /* secondary hotkey */
  11290.                            menu_func,     /* function to call if
  11291.                                              chosen */
  11292.                          " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  11293.                          " New"         ,3, 'N',0,menu_func,
  11294.                          " Save      F2",4, 'S',F2,menu_func,
  11295.                          " Write to    ",5, 'W',0,menu_func,
  11296.                          " Directory   ",6, 'D',0,menu_func,
  11297.                          " Change Dir"  ,7, 'C',0,menu_func,
  11298.                          " OS shell"    ,8, 'O',0,menu_func,
  11299.                          " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  11300.  
  11301.                         /* Terminate with a CWL_NULL and 0 */
  11302.  
  11303.                          CWL_NULL,0};
  11304.  
  11305.  
  11306.  
  11307.  
  11308.          Dynamic Method
  11309.          --------------
  11310.  
  11311.          #include "menu.h"
  11312.          #define NUMENTRIES 9
  11313.  
  11314.          POPUP_MENU_ENTRY_PTR menu_array; /* Notice that we have a
  11315.                                              pointer to what
  11316.                                              will be an array of
  11317.                                              POPUP_MENU_ENTRY's
  11318.                                           */
  11319.          POPUP_MENU_PTR p;
  11320.  
  11321.          main()
  11322.          {
  11323.            WindowInitializeSystem();
  11324.  
  11325.            /* Initialize with at least number of total entries */
  11326.            menu_array = PopupAllocate(NUMENTRIES);
  11327.  
  11328.            /* Call function to create entries in
  11329.               menu_array sequentially */
  11330.            PopupCreateEntry(menu_array, /* POPUP_MENU_ENTRY pointer */
  11331.                        1,            /* entry number */
  11332.  
  11333.           /* The rest of the arguments are just like the old method */
  11334.                        " Load    F3", /* menu string */
  11335.                        1,             /* row number */
  11336.                        'L',           /* hotkey letter */
  11337.                        F3,            /* secondary hotkey */
  11338.                        menu_func);    /* function to perform */
  11339.  
  11340.  
  11341.            /* do rest of the entries */
  11342.            PopupCreateEntry(menu_array,2," Pick  Alt-F3",2,'P',ALTF3,
  11343.                             menu_func);
  11344.  
  11345.  
  11346.  
  11347.          Page 175          The C Window Library               Page 175
  11348.  
  11349.            PopupCreateEntry(menu_array,3," New",3,'N',0,menu_func);
  11350.  
  11351.            PopupCreateEntry(menu_array,4," Save      F2",4,'S',F2,
  11352.                             menu_func);
  11353.  
  11354.            PopupCreateEntry(menu_array,5," Write to    ",5,'W',0,
  11355.                             menu_func);
  11356.  
  11357.            PopupCreateEntry(menu_array,6," Directory   ",6,'D',0,
  11358.                             menu_func);
  11359.  
  11360.            PopupCreateEntry(menu_array,7," Change Dir  ",7,'C',0,
  11361.                             menu_func);
  11362.  
  11363.            PopupCreateEntry(menu_array,8," OS Shell    ",8,'O',0,
  11364.                             menu_func);
  11365.  
  11366.            PopupCreateEntry(menu_array,9," Quit  Alt-X ",9,'Q',ALTX,0,
  11367.                             menu_func);
  11368.  
  11369.            /* end all of the menu entries */
  11370.            PopupEntryEnd(menu_array,NUMENTRIES);
  11371.  
  11372.            /* create menu */
  11373.            p = PopupCreateMenu(menu_array, ... /* other arguments */);
  11374.  
  11375.            /* ... */
  11376.  
  11377.            /* Dispose of menu entries created */
  11378.            PopupDeallocate(menu_array);
  11379.          }
  11380.  
  11381.  
  11382.          The difference between the above method and the method used
  11383.          to globally initialize an array are the following:
  11384.  
  11385.          1) The variable type for menu_array is POPUP_MENU_ENTRY_PTR,
  11386.             not POPUP_MENU_ENTRY as the normal method would have done.
  11387.  
  11388.          2) You must call the PopupAllocate() function to allocate
  11389.             space for the number of entries desired.  If you do not
  11390.             call PopupAllocate(), you will surely get a memory
  11391.             overwrite error.  The return value to PopupAllocate() must
  11392.             be assigned to a POPUP_MENU_ENTRY_PTR, as the above
  11393.             example shows.
  11394.  
  11395.             The array of menu entries are allocated from the heap at
  11396.             runtime, as opposed to the static method which sets up the
  11397.             memory scheme at link time.
  11398.  
  11399.          3) The next thing you must do is to fill in the entry
  11400.             information by calling the PopupCreateEntry() function.
  11401.             The first argument to the PopupCreateEntry() function is
  11402.             the POPUP_MENU_ENTRY_PTR.  The second argument is the
  11403.             entry number to assign this information to.  The rest of
  11404.  
  11405.  
  11406.  
  11407.          Page 176          The C Window Library               Page 176
  11408.  
  11409.             the arguments are the same order as the usual method i.e.
  11410.             menu string, row, hotkey, etc.  PopupCreateEntry() is
  11411.             called for each field desired.
  11412.  
  11413.          4) The PopupEndEntry() function must be called to terminate
  11414.             the list of entries.  The first argument is the
  11415.             POPUP_MENU_ENTRY_PTR, and the second argument is the total
  11416.             number of entries defined.
  11417.  
  11418.          5) You should call PopupDeallocate() to free the memory
  11419.             assigned to the array of menu_entries.  The only argument
  11420.             to PopupDeallocate() is the POPUP_MENU_ENTRY_PTR.  Only
  11421.             call PopupDeallocate() after you have called
  11422.             PopupMenuFree() or any function that disposes of the
  11423.             POPUP_MENU_PTR.
  11424.  
  11425.  
  11426.          All of these functions except for PopupAllocate() have no
  11427.          return values.  The PopupAllocate() function returns a
  11428.          POPUP_MENU_ENTRY_PTR if successful, and a null pointer if
  11429.          unsuccessful.
  11430.  
  11431.          The advantages of using the above method over the first
  11432.          method is that POPUP_MENU_ENTRY's are dynamically allocated
  11433.          rather than statically declared at compile time.  This allows
  11434.          the programmer to create loops to set up the entries, read
  11435.          entry information from a file and assign this info to a
  11436.          POPUP_MENU_ENTRY, etc.
  11437.  
  11438.  
  11439.          You could also do the following:
  11440.  
  11441.          #include "menu.h"
  11442.          #define NUMENTRIES 9
  11443.  
  11444.          POPUP_MENU_ENTRY menu_array[NUMENTRIES+1]; /* We must have at
  11445.                                                  least 1 more than the
  11446.                                                  number of entries */
  11447.  
  11448.          POPUP_MENU_PTR p;
  11449.  
  11450.          main()
  11451.          {
  11452.             /* ... */
  11453.  
  11454.          /* Call function to create entries
  11455.             in menu_array sequentially */
  11456.            PopupCreateEntry(menu_array,1," Load    F3",1,'L',F3,
  11457.                             menu_func);
  11458.  
  11459.            PopupCreateEntry(menu_array,2," Pick  Alt-F3",2,'P',ALTF3,
  11460.                             menu_func);
  11461.  
  11462.            PopupCreateEntry(menu_array,3," New",3,'N',0,menu_func);
  11463.  
  11464.  
  11465.  
  11466.  
  11467.          Page 177          The C Window Library               Page 177
  11468.  
  11469.            PopupCreateEntry(menu_array,4," Save      F2",4,'S',F2,
  11470.                             menu_func);
  11471.  
  11472.            PopupCreateEntry(menu_array,5," Write to    ",5,'W',0,
  11473.                             menu_func);
  11474.  
  11475.            PopupCreateEntry(menu_array,6," Directory   ",6,'D',0,
  11476.                             menu_func);
  11477.  
  11478.            PopupCreateEntry(menu_array,7," Change Dir  ",7,'C',0,
  11479.                             menu_func);
  11480.  
  11481.            PopupCreateEntry(menu_array,8," OS Shell    ",8,'O',0,
  11482.                             menu_func);
  11483.  
  11484.            PopupCreateEntry(menu_array,9," Quit  Alt-X ",9,'Q',ALTX,0,
  11485.                             menu_func);
  11486.  
  11487.  
  11488.            /* end all of the menu entries */
  11489.            PopupEntryEnd(menu_array,NUMENTRIES);
  11490.          }
  11491.  
  11492.          The method above does not call PopupAllocate() because the
  11493.          number of entries was already determined and an array was
  11494.          already set up at compile time.
  11495.  
  11496.          PopupCreateEntry() is called for each menu entry as before,
  11497.          and PopupEntryEnd() is called to terminate the menu entries.
  11498.  
  11499.          To use this method, you must declare an array of menu entries
  11500.          with at least one more than the desired number of entries.
  11501.          Also note that PopupDeallocate() MUST NOT be called because
  11502.          the array of menu entries was not created with
  11503.          PopupAllocate().
  11504.  
  11505.  
  11506.  
  11507.  
  11508.  
  11509.  
  11510.  
  11511.  
  11512.  
  11513.  
  11514.  
  11515.  
  11516.  
  11517.  
  11518.  
  11519.  
  11520.  
  11521.  
  11522.  
  11523.  
  11524.  
  11525.  
  11526.  
  11527.          Page 178          The C Window Library               Page 178
  11528.  
  11529.          PopupCreateMenu() function
  11530.          --------------------------
  11531.  
  11532.          Now that you have created the POPUP_MENU_ENTRY's, and defined
  11533.          the color scheme, it is time to wrap all of these loose ends
  11534.          in one package.  The next step is to call the
  11535.          PopupCreateMenu() function.  This function combines all of
  11536.          the POPUP_MENU_ENTRY's, the colors you have defined, and
  11537.          other information into one entity called a POPUP_MENU_PTR.
  11538.  
  11539.          A POPUP_MENU_PTR is a pointer to a popup menu structure.
  11540.          Just like a WPOINTER is a pointer to a window, a
  11541.          POPUP_MENU_PTR is used to reference the popup menu.
  11542.  
  11543.          A prototype of the call to PopupCreateMenu() is as follows:
  11544.  
  11545.          POPUP_MENU_PTR PopupCreateMenu(POPUP_MENU_ENTRY *p,
  11546.                                         unsigned *color, int row,
  11547.                                         int col, int height,
  11548.                                         unsigned options,
  11549.                                         WPOINTER (*wfunc)(),
  11550.                                         VWPOINTER (*vfunc)())
  11551.  
  11552.          To illustrate how to use this call, let's use the
  11553.          POPUP_MENU_ENTRY's and colors created in the previous
  11554.          examples:
  11555.  
  11556.          #include "menu.h"
  11557.          int menu_func();
  11558.          POPUP_MENU_ENTRY menu_items[] = {
  11559.                  " Load      F3", 1,'L',F3,menu_func,
  11560.                  " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  11561.                  " New"         ,3, 'N',0,menu_func,
  11562.                  " Save      F2",4, 'S',F2,menu_func,
  11563.                  " Write to    ",5, 'W',0,menu_func,
  11564.                  " Directory   ",6, 'D',0,menu_func,
  11565.                  " Change Dir"  ,7, 'C',0,menu_func,
  11566.                  " OS shell"    ,8, 'O',0,menu_func,
  11567.                  " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  11568.                  CWL_NULL,0};
  11569.  
  11570.          unsigned int menu_colors[5];
  11571.          POPUP_MENU_PTR p;
  11572.  
  11573.          main()
  11574.          {
  11575.            WindowInitializeSystem();
  11576.  
  11577.           /* define colors */
  11578.            menu_colors[ENTRYCOLOR] =
  11579.                   CREATE_VIDEO_ATTRIBUTE(black,white);
  11580.            menu_colors[BORDERCOLOR] =
  11581.                   CREATE_VIDEO_ATTRIBUTE(black,white);
  11582.            menu_colors[HOTKEYCOLOR] =
  11583.                   CREATE_VIDEO_ATTRIBUTE(blue,white);
  11584.            menu_colors[HIGHLIGHTCOLOR] =
  11585.                   CREATE_VIDEO_ATTRIBUTE(black,cyan);
  11586.  
  11587.          Page 179          The C Window Library               Page 179
  11588.  
  11589.            menu_colors[UNAVAILCOLOR] =
  11590.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  11591.  
  11592.           /* create a POPUP_MENU_PTR */
  11593.  
  11594.           WindowSaveInitial(0);  /* Save initial screen    */
  11595.           p = PopupCreateMenu(menu_items,menu_colors,
  11596.                               10,10,9,NO_POPUP_OPTIONS,
  11597.                               WNULLFN,VWNULLFN);
  11598.           /* rest of the code */
  11599.          }
  11600.  
  11601.  
  11602.          In the example above there are two function calls that must
  11603.          be done before calling PopupCreateMenu().  The first
  11604.          mandatory function is WindowInitializeSystem().  The other
  11605.          function must be WindowSaveInitial() The
  11606.          WindowInitializeSystem() function must be called to
  11607.          initialize global variables used by the menu manager.  The
  11608.          WindowSaveInitial() function is a mandatory function because
  11609.          the PopupCreateMenu() function creates windows and virtual
  11610.          windows and assumes that the base screen has been saved.
  11611.  
  11612.          The example above declares the variable p to be a
  11613.          POPUP_MENU_PTR.  This POPUP_MENU_PTR is going to be used to
  11614.          reference the popup menu throughout the program.
  11615.  
  11616.          The first argument to PopupCreateMenu() is a pointer to the
  11617.          first POPUP_MENU_ENTRY.  In the above example,  menu_items is
  11618.          a pointer to the first POPUP_MENU_ENTRY.
  11619.  
  11620.          The second argument is a pointer to the array of colors.  In
  11621.          our example, menu_colors is our array of colors.
  11622.  
  11623.          The third and fourth arguments denote the row and column to
  11624.          place the upper left hand corner of the popup menu window.
  11625.  
  11626.          The fifth argument is the height of the popup menu window.
  11627.          If the height of the window will not accommodate all of the
  11628.          menu items, the menu manager will scroll the window so that
  11629.          the entries that are obscured come into view.
  11630.  
  11631.          The sixth argument are various popup menu options that are
  11632.          assigned to the popup menus which are defined below.
  11633.  
  11634.  
  11635.          Popup Menu Options
  11636.          ------------------
  11637.  
  11638.          By default the menu manager assumes the following things:
  11639.  
  11640.          1)  The highlight bar does not wrap if the user wants to move
  11641.              the bar past the last entry, or before the first entry.
  11642.  
  11643.  
  11644.  
  11645.  
  11646.  
  11647.          Page 180          The C Window Library               Page 180
  11648.  
  11649.          2)  The menu will be hidden from the screen when a selection
  11650.              is made and will reappear when control is returned to
  11651.              the menu manager.
  11652.  
  11653.          3)  A function is automatically invoked when the hotkey is
  11654.              pressed instead of calling a user-defined function
  11655.              which will tell the menu manager whether the menu entry
  11656.              is to be executed.
  11657.  
  11658.          4)  The popup menu window is hidden when the menu manager
  11659.              returns control to the calling function.
  11660.  
  11661.          5)  The highlight bar will skip unavailable entries.
  11662.  
  11663.          6)  The menu manager does not recognize enhanced keys (F11,
  11664.              F12, etc.).
  11665.  
  11666.          7)  The mouse will not be used to move the highlight bar.
  11667.  
  11668.          8)  Scroll characters will not be displayed on the popup
  11669.              window.  The scroll characters allow the user to scroll
  11670.              through the options with a mouse.
  11671.  
  11672.  
  11673.          The last two options are only available if you have a
  11674.          Microsoft compatible mouse, and the mouse is activated.
  11675.  
  11676.          If the constant NO_POPUP_OPTIONS is used, the assumptions
  11677.          above are used.  If you want to override the above defaults,
  11678.          use the following options:
  11679.  
  11680.  
  11681.             Option Name              Definition
  11682.             -----------              ----------
  11683.              POPUPWRAP             Highlight bar wrapping.
  11684.  
  11685.              POPUPSTATIC           Do not hide menu when selection is
  11686.                                    made.
  11687.  
  11688.              POPUPCONFIRM          Confirmation when selection is made
  11689.                                    via hotkey.
  11690.  
  11691.              POPUPDISPLAY          Display menu even after exit.
  11692.  
  11693.              POPUPOVERRIDE         Accept Unavailable entries.
  11694.  
  11695.              POPUPENHANCEDKEY      Recognize enhanced keys.
  11696.  
  11697.              POPUPMOUSE            Use the mouse to select entries.
  11698.  
  11699.              POPUPMOUSESCROLL      Use the mouse to scroll through
  11700.                                    entries by placing mouse on
  11701.                                    hotspots.
  11702.  
  11703.          As was stated before, the last two options, POPUPMOUSE and
  11704.  
  11705.  
  11706.  
  11707.          Page 181          The C Window Library               Page 181
  11708.  
  11709.          POPUPSCROLLCHARS, can only be used if you have a mouse
  11710.          installed, and the mouse is activated.  More information on
  11711.          these two options is given in the USING A MOUSE section.
  11712.  
  11713.          By turning the above options "on" the following is assumed:
  11714.  
  11715.          1)  POPUPWRAP will wrap the highlight bar if the user wants
  11716.              to move the bar past the last entry or before the first
  11717.              entry.
  11718.  
  11719.          2)  POPUPSTATIC will not hide the menu when a selection is
  11720.              made.
  11721.  
  11722.          3)  POPUPCONFIRM will call a user-defined function before
  11723.              invoking the hotkey that was selected.  This function
  11724.              will then return an integer back to the menu manager
  11725.              informing whether the function selected should be
  11726.              invoked, or the request should be rejected.  There is
  11727.              more information on this option in the SETTING OPTIONS
  11728.              IN POPUP MENUS section below.
  11729.  
  11730.          4)  POPUPDISPLAY will not hide the popup window when the menu
  11731.              manager returns control to the calling function.
  11732.  
  11733.          5)  POPUPOVERRIDE will make the menu manager accept
  11734.              unavailable entries.
  11735.  
  11736.          6)  POPUPENHANCEDKEY will inform the menu manager that
  11737.              enhanced keys will be recognized.
  11738.  
  11739.          7)  POPUPMOUSE allows the use of a mouse to make selections.
  11740.  
  11741.          8)  POPUPMOUSESCROLL allows the user to scroll through the
  11742.              options using a mouse.
  11743.  
  11744.          You can also set multiple options by using a bitwise OR (|).
  11745.          For example:
  11746.  
  11747.            p = PopupCreateMenu(arg1,arg2,arg3,arg4,arg5,
  11748.                POPUPWRAP | POPUPSTATIC | POPUPCONFIRM,arg7,arg8)
  11749.  
  11750.          will set options POPUPWRAP, POPUPSTATIC, and POPUPCONFIRM
  11751.          defined above.
  11752.  
  11753.  
  11754.  
  11755.          The last two arguments to PopupCreateMenu() are defined in
  11756.          the next sections.
  11757.  
  11758.  
  11759.          Default Popup Window and Creating Your own Windows
  11760.          --------------------------------------------------
  11761.  
  11762.          The sixth argument to the PopupCreateMenu() function is a
  11763.          pointer to a function that will open a popup menu window.  If
  11764.          this is a NULL function pointer (WNULLFN), the menu manager
  11765.  
  11766.  
  11767.          Page 182          The C Window Library               Page 182
  11768.  
  11769.          will create a window.  For most applications, the window that
  11770.          the menu manager will create is adequate.  The menu manager
  11771.          uses these defaults when making the popup window:
  11772.  
  11773.          - A bordered window with the border consisting of single
  11774.            lines (SINGLEBOX).
  11775.  
  11776.          - The width of the window is determined by the longest
  11777.            entry_name in the POPUP_MENU_ENTRY's.
  11778.  
  11779.  
  11780.          If you want to create your own popup menu window, your
  11781.          function must return a WPOINTER.  Inside your function you
  11782.          must create and open a window using WindowInitialize() and
  11783.          WindowOpen().  For most applications, you do not have to
  11784.          display the window, instead the menu manager can do the
  11785.          displaying and hiding of the windows.
  11786.  
  11787.          Here is an example of creating your own custom window
  11788.          function:
  11789.  
  11790.          #include "menu.h"
  11791.          /* Other includes and menu stuff */
  11792.          WPOINTER my_open();
  11793.          POPUP_MENU_PTR p;
  11794.          main()
  11795.          {
  11796.             /*   Other code */
  11797.            p =
  11798.            PopupCreateMenu(menu_items,menu_colors,10,10,9,
  11799.                            my_open,WNULLFN);
  11800.             /* More code */
  11801.          }
  11802.  
  11803.          WPOINTER my_open()
  11804.          {
  11805.            WPOINTER w;
  11806.            w = WindowInitialize(NOBORDER,1,1,20,10,BLACKONWHITE,
  11807.                                 BLACKONWHITE,"");
  11808.            WindowOpen(w);
  11809.            return w;       /* May be WIN_NULL_PTR, but must return to
  11810.                               PopupCreateMenu() */
  11811.          }
  11812.  
  11813.          The example above lets the menu manager know that the window
  11814.          creation function is a user written function called my_open.
  11815.          The row, column and height arguments (arguments 3, 4 and 5)
  11816.          of PopupCreateMenu() will be ignored when using a custom
  11817.          window function.  The row, column and height parameters used
  11818.          to create the window in the call to WindowInitialize() in
  11819.          my_window() will take precedence over the arguments 3, 4, and
  11820.          5 used in PopupCreateMenu().
  11821.  
  11822.  
  11823.  
  11824.  
  11825.  
  11826.  
  11827.          Page 183          The C Window Library               Page 183
  11828.  
  11829.          Default Virtual Window and
  11830.          Creating Your own Virtual Windows
  11831.          ---------------------------------
  11832.  
  11833.          The last argument to PopupCreateMenu() is a pointer to a
  11834.          function that will return a VWPOINTER.  This function creates
  11835.          the virtual window used to write the menu entries.  If this
  11836.          is a NULL function pointer (VWNULLFN), the menu manager will
  11837.          create the virtual window.  If you do specify a function,
  11838.          your virtual window must have enough rows to hold all of the
  11839.          POPUP_MENU_ENTRY's, and be wide enough to hold the length of
  11840.          the longest entry_name.
  11841.  
  11842.          When the menu manager creates the virtual window, the
  11843.          following defaults are assumed:
  11844.  
  11845.           a) the virtual window has its own video attributes.
  11846.           b) Must be large enough to hold all the POPUP_MENU_ENTRY's.
  11847.  
  11848.          Your custom function should create a virtual window which
  11849.          follows both rules.
  11850.  
  11851.          You must also make sure that the virtual window was created
  11852.          and opened successfully.  If the virtual window cannot be
  11853.          created because of a lack of memory, you must return the NULL
  11854.          virtual window pointer instead.  From there,
  11855.          PopupCreateMenu() will do any cleaning up and will return
  11856.          with a null POPUP_MENU_PTR.
  11857.  
  11858.          My last advice when calling the PopupCreateMenu() function is
  11859.          that your best bet is to let the menu manager create the
  11860.          windows and virtual windows.  You can always resize, change
  11861.          border types, etc. later on.  Since virtual window's are not
  11862.          visible anyway, it makes sense to let the menu manager
  11863.          determine how the virtual window should be created.  The last
  11864.          two arguments to the PopupCreateMenu() function are for those
  11865.          programmers who need full control of window, and virtual
  11866.          window management.
  11867.  
  11868.  
  11869.  
  11870.          Accessing Popup Windows and Virtual Windows
  11871.          -------------------------------------------
  11872.  
  11873.          After calling the PopupCreateMenu() function, you can access
  11874.          the popup window by using the POPUP_WINDOW() macro.  In the
  11875.          above example, p is the POPUP_MENU_PTR and the value of
  11876.          POPUP_WINDOW(p) is a pointer to the popup menu's window.  If
  11877.          you want to change borders move, slide, or anything you can
  11878.          do with normal windows, you must access the popup window in
  11879.          this way.
  11880.  
  11881.          For example, if you want to change the border of the popup
  11882.          window you would do the following:
  11883.  
  11884.  
  11885.  
  11886.  
  11887.          Page 184          The C Window Library               Page 184
  11888.  
  11889.          p = PopupCreateMenu(...  /* other arguments */ )
  11890.              WindowDrawBorder(POPUP_WINDOW(p),DOUBLEBOX);
  11891.  
  11892.          The example calls WindowDrawBorder() to change the border of
  11893.          the popup window.
  11894.  
  11895.          If you want to write information to the virtual window
  11896.          created by the PopupCreateMenu() function, you can access the
  11897.          virtual window by using the POPUP_VIRTUAL_WINDOW() macro.  By
  11898.          accessing the popup-menu's virtual window, you can read and
  11899.          write to and from the virtual window.  This is very useful if
  11900.          you want to draw horizontal lines in your menu.  An example
  11901.          would be as follows:
  11902.  
  11903.              char *h = "----------------------";
  11904.  
  11905.              /* ...Some code... */
  11906.  
  11907.              p = PopupCreateMenu(menu_items,menu_colors,10,10,9,
  11908.                                  WNULLFN,VWNULLFN);
  11909.              VirtualWriteString(POPUP_VIRTUAL_WINDOW(p),h,8,1);
  11910.  
  11911.  
  11912.          Warnings
  11913.          --------
  11914.  
  11915.          Do not call WindowFree(), WindowClose() or VirtualFree() on
  11916.          the window or the virtual window of the popup menu.  The menu
  11917.          manager will call these functions when PopupMenuFree() is
  11918.          called.  If you close the popup window, or the virtual window
  11919.          on an active menu, the menu manager will assume that these
  11920.          windows still exist.  Doing so will almost guarantee your
  11921.          application will bomb out.
  11922.  
  11923.  
  11924.          Return Values for PopupCreateMenu()
  11925.          -----------------------------------
  11926.  
  11927.          If there are no errors, PopupCreateMenu() returns a valid
  11928.          POPUP_MENU_PTR pointer.  If there is an error when
  11929.          PopupCreateMenu() is called, a null POPUP_MENU_PTR is
  11930.          returned.  Here are the possible reasons why an error has
  11931.          occurred:
  11932.  
  11933.            1) There is not enough memory to allocate for the
  11934.               POPUP_MENU_PTR or its internal data structures.
  11935.  
  11936.            2) There is not enough memory to allocate for the popup
  11937.               window.
  11938.  
  11939.            3) There is not enough memory to allocate for the virtual
  11940.               window.
  11941.  
  11942.            4) The popup window's size was invalid.
  11943.  
  11944.  
  11945.  
  11946.  
  11947.          Page 185          The C Window Library               Page 185
  11948.  
  11949.          Problems 1,2, and 3 all are caused by a lack of heap memory.
  11950.          Problem 4 stems from having invalid parameters in the
  11951.          PopupCreateMenu().  The arguments that are suspect are the
  11952.          third, fourth, and fifth arguments.  To remedy this problem,
  11953.          adjust these arguments such that the window can fit on the
  11954.          screen.
  11955.  
  11956.          For all of the above conditions, you can get the actual error
  11957.          code by checking the value of the global integer
  11958.          window_error_code.  If window_error_code is equal to
  11959.          NO_HEAP_MEM, then condition 1, 2, or 3 has occurred.  If it
  11960.          is equal to BAD_WINDOW_SIZE, then condition 4 has occurred.
  11961.  
  11962.          If you have a custom window or virtual window opening
  11963.          function, it is your responsibility to check the error
  11964.          conditions that may occur, and return correct values or null
  11965.          pointers if you cannot rectify the error in your custom
  11966.          routine.
  11967.  
  11968.  
  11969.          Here is an example:
  11970.  
  11971.          Example:
  11972.               int status;
  11973.               POPUP_MENU_PTR p;
  11974.               p = PopupCreateMenu(...);
  11975.               if (p == (POPUP_MENU_PTR)0) {
  11976.                 if (window_error_code == NO_HEAP_MEM)
  11977.                    /* ... Condition 1,2, or 3 occurred */
  11978.                 else
  11979.                   /* Condition 4 occurred */
  11980.               }
  11981.  
  11982.  
  11983.  
  11984.  
  11985.  
  11986.  
  11987.  
  11988.  
  11989.  
  11990.  
  11991.  
  11992.  
  11993.  
  11994.  
  11995.  
  11996.  
  11997.  
  11998.  
  11999.  
  12000.  
  12001.  
  12002.  
  12003.  
  12004.  
  12005.  
  12006.  
  12007.          Page 186          The C Window Library               Page 186
  12008.  
  12009.                      SELECTING FROM POPUP MENUS
  12010.                      --------------------------
  12011.  
  12012.          We have now created the popup menu.  Now how do we get the
  12013.          menu manager to act on our popup window?  The answer is the
  12014.          PopupSelectMenu() function.
  12015.  
  12016.  
  12017.          PopupSelectMenu() function
  12018.          --------------------------
  12019.  
  12020.          The PopupSelectMenu() function displays the popup window, and
  12021.          allows the user to move the highlight bar until he/she has
  12022.          placed the bar on the desired option, or the user presses a
  12023.          hotkey to invoke one of the entries.
  12024.  
  12025.          Before the call to the PopupSelectMenu(), nothing has been
  12026.          displayed.  This means that you can resize the popup window,
  12027.          change borders, write strings to the popup menus virtual
  12028.          window, etc. while everything is hidden away from view.  The
  12029.          only time when the popup menu is displayed is when the call
  12030.          to PopupSelectMenu() is made (or unless you have displayed
  12031.          the popup window yourself using WindowDisplay()).
  12032.  
  12033.          A prototype of the call to PopupSelectMenu() is as follows:
  12034.  
  12035.          int PopupSelectMenu(POPUP_MENU_PTR p, int rank,
  12036.                              unsigned start)
  12037.  
  12038.          The first argument is the POPUP_MENU_PTR.  The second
  12039.          argument is the rank of the popup window.  As with other
  12040.          windows, the rank determines how the window will be situated
  12041.          on the screen with respect to the other windows.  The last
  12042.          argument is the number of the menu entry of where the
  12043.          highlight bar should be situated.  Usually this is 1, but
  12044.          this will give you the option to start on any one of the menu
  12045.          entries.  If the start value is out of bounds (say you have
  12046.          specified start to be 5 while there are only 4 menu entries)
  12047.          the menu manager will default to the first menu option.
  12048.  
  12049.          Now let's put everything together:
  12050.  
  12051.  
  12052.          #include "menu.h"
  12053.          int menu_func();
  12054.  
  12055.          POPUP_MENU_ENTRY menu_items[] = {
  12056.               " Load      F3",1,'L',F3,menu_func,
  12057.               " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  12058.               " New"         ,3, 'N',0,menu_func,
  12059.               " Save      F2",4, 'S',F2,menu_func,
  12060.               " Write to    ",5, 'W',0,menu_func,
  12061.               " Directory   ",6, 'D',0,menu_func,
  12062.               " Change Dir"  ,7, 'C',0,menu_func,
  12063.               " OS shell"    ,8, 'O',0,menu_func,
  12064.  
  12065.  
  12066.  
  12067.          Page 187          The C Window Library               Page 187
  12068.  
  12069.               " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  12070.              CWL_NULL,0};
  12071.  
  12072.          unsigned int menu_colors[5];
  12073.          POPUP_MENU_PTR p;
  12074.  
  12075.          main()
  12076.          {
  12077.            WindowInitializeSystem();
  12078.            WindowSaveInitial(0);
  12079.           /* define colors */
  12080.            menu_colors[ENTRYCOLOR] =
  12081.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  12082.            menu_colors[BORDERCOLOR] =
  12083.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  12084.            menu_colors[HOTKEYCOLOR] =
  12085.                   CREATE_VIDEO_ATTRIBUTE(white,blue);
  12086.            menu_colors[HIGHLIGHTCOLOR] =
  12087.                   CREATE_VIDEO_ATTRIBUTE(cyan,black);
  12088.            menu_colors[UNAVAILCOLOR] =
  12089.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  12090.  
  12091.           /* create a POPUP_MENU_PTR */
  12092.           p = PopupCreateMenu(menu_items,menu_colors, 1,1,6,
  12093.                               POPUPSTATIC,WNULLFN,VWNULLFN);
  12094.           PopupSelectMenu(p,  /* POPUP_MENU_PTR */
  12095.                             1,  /* rank of popup window */
  12096.                             1   /* menu entry to start on */
  12097.                            );
  12098.          }
  12099.  
  12100.  
  12101.          int menu_func(POPUP_MENU_PTR p, unsigned which)
  12102.          {
  12103.            WPOINTER w;
  12104.            w = WindowInitialize(BORDER,15,15,40,4,
  12105.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  12106.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  12107.                                 SINGLEBOX);
  12108.            WindowOpen(w);
  12109.            WindowClear(w);
  12110.            WindowPrintf(w,"You have selected %s",
  12111.                         POPUP_ENTRY_STRING(p,which));
  12112.            WindowWriteCenterString(w,"Press a key to continue",3);
  12113.            WindowDisplay(w,1,NOEFFECT);
  12114.            GET_KEY();
  12115.            WindowFree(w,NOEFFECT);
  12116.            if (which == 9)
  12117.              return POPUP_EXIT;
  12118.            else
  12119.            return POPUP_CONTINUE;
  12120.          }
  12121.  
  12122.          The above example has a call to PopupSelectMenu().  The
  12123.          arguments passed are p as the POPUP_MENU_PTR, a window rank
  12124.  
  12125.  
  12126.  
  12127.          Page 188          The C Window Library               Page 188
  12128.  
  12129.          of 1, and a starting position of 1.  The POPUP_ENTRY_STRING()
  12130.          macro in the menu_func() function returns the entry string
  12131.          for the particualr menu entry.  The first argument is the
  12132.          POPUP_MENU_PTR and the second argument is the entry number.
  12133.  
  12134.  
  12135.  
  12136.  
  12137.          Values passed to menu function
  12138.          ------------------------------
  12139.  
  12140.          When a selection is made, the menu manager will call the
  12141.          function defined for the selection, and pass two arguments to
  12142.          this function.  The first argument passed is the
  12143.          POPUP_MENU_PTR of the current popup menu and the second
  12144.          argument is the number of the entry selected.  Entry numbers
  12145.          are numbered from 1 to the highest entry in the menu.  For
  12146.          example, if the " Load F3" entry is selected, the menu
  12147.          manager will pass the POPUP_MENU_PTR p, and a 1 to func().
  12148.          If " Pick ALT-F3" is chosen, the menu manager passes a 2 as
  12149.          the second argument to func() etc.
  12150.  
  12151.  
  12152.  
  12153.  
  12154.          Values returned to menu manager
  12155.          -------------------------------
  12156.  
  12157.          The user function must return an integer back to the menu
  12158.          manager.  If the value returned to the menu manager is
  12159.          POPUP_EXIT, the menu manager will exit from the current menu
  12160.          and will return control back to the function that called it.
  12161.          If the return value is POPUP_CONTINUE, the menu continues to
  12162.          process selections.
  12163.  
  12164.          The menu_func() function defined above creates a window,
  12165.          displays the entry you have chosen, and returns a value back
  12166.          to the menu manager.  If the value is POPUP_EXIT, the menu
  12167.          manager returns control back to the function that called it.
  12168.          In this case, main() called PopupSelectMenu().  A return
  12169.          value of POPUP_CONTINUE will cause the menu manager to let
  12170.          the user make another selection.
  12171.  
  12172.          The menu_func() function is a simple implementation.  However
  12173.          your function can do much more sophisticated things,
  12174.          including opening other popup menus.  If another popup menu
  12175.          is called while in another popup menu, the new popup menu
  12176.          gets its own menu manager and will not interfere with the
  12177.          original menu manager.  This is good if a menu function will
  12178.          call another menu function.
  12179.  
  12180.  
  12181.  
  12182.  
  12183.  
  12184.  
  12185.  
  12186.  
  12187.          Page 189          The C Window Library               Page 189
  12188.  
  12189.          Return Values for PopupSelectMenu()
  12190.          -----------------------------------
  12191.  
  12192.          If no errors occurred when PopupSelectMenu() is called the
  12193.          menu manager returns NO_ERROR when the menu is closed.  There
  12194.          are three possibilities for errors when calling
  12195.          PopupSelectMenu().  Here are the three possible errors:
  12196.  
  12197.          1) The popup menus window does not exist.
  12198.  
  12199.          2) The popup menus window is not opened.
  12200.  
  12201.          3) The virtual window does not exist.
  12202.  
  12203.          The first error occurred because the PopupCreateMenu()
  12204.          function or your custom window function could not initialize
  12205.          the popup menu window, you inadvertently called WindowFree()
  12206.          on the popup menu's window, or you are overwriting data with
  12207.          a stray pointer.
  12208.  
  12209.          Error 2 can occur if the you inadvertently called
  12210.          WindowClose() on the popup menu's window, or you are
  12211.          overwriting data with a stray pointer.
  12212.  
  12213.          Error 3 can occur if PopupCreateMenu() or your custom virtual
  12214.          window function could not create the virtual window, or a
  12215.          stray pointer is overwriting data.
  12216.  
  12217.          For all of the above conditions, you can get the actual error
  12218.          code by checking the value of the global integer
  12219.          window_error_code or by checking the return value of
  12220.          PopupSelectMenu().  Here is a list of return values and their
  12221.          corresponding reasons:
  12222.  
  12223.            Return Value               Condition
  12224.            ------------               ---------
  12225.            BAD_WINDOW                    1
  12226.            WINDOW_NOT_OPEN               2
  12227.            BAD_V_WINDOW                  3
  12228.  
  12229.  
  12230.  
  12231.  
  12232.  
  12233.  
  12234.  
  12235.  
  12236.  
  12237.  
  12238.  
  12239.  
  12240.  
  12241.  
  12242.  
  12243.  
  12244.  
  12245.  
  12246.  
  12247.          Page 190          The C Window Library               Page 190
  12248.  
  12249.                    SETTING OPTIONS IN POPUP MENUS
  12250.                    ------------------------------
  12251.  
  12252.          In addition to setting options using the PopupCreateMenu()
  12253.          function, you can turn on and off options at any time using
  12254.          the PopupSetOptions() function.
  12255.  
  12256.  
  12257.          The PopupSetOptions() function
  12258.          ------------------------------
  12259.  
  12260.          The PopupSetOptions() function turns either one or more of
  12261.          the above options on or off.  The prototype to the call is as
  12262.          follows:
  12263.  
  12264.          int PopupSetOptions(POPUP_MENU_PTR p, int option, int switch)
  12265.  
  12266.          The first argument is the POPUP_MENU_PTR.  The second
  12267.          argument are the options that you wish to change.  The
  12268.          constants that describe the options are exactly the same as
  12269.          the ones described in PopupCreateMenu().  The third argument
  12270.          is whether you want to switch the options on or off.
  12271.  
  12272.            Here are some sample calls to PopupSetOptions():
  12273.  
  12274.              a) PopupSetOptions(p,POPUPWRAP,1)
  12275.              b) PopupSetOptions(p,POPUPSTATIC,1)
  12276.              c) PopupSetOptions(p,POPUPCONFIRM,1)
  12277.              d) PopupSetOptions(p,POPUPSTATIC,0)
  12278.              e) PopupSetOptions(p,POPUPDISPLAY,1)
  12279.              f) PopupSetOptions(p,POPUPOVERRIDE,1)
  12280.              g) PopupSetOptions(p,POPUPENHANCEDKEY,1)
  12281.  
  12282.          The third argument is 1 for "on", 0 for "off".
  12283.  
  12284.          Example a) sets the highlight bar so that it will wrap.
  12285.  
  12286.          Example b) informs the menu manager that the menu will not be
  12287.          hidden when a selection is made.
  12288.  
  12289.          Example c) will tell the menu manager to call a user defined
  12290.          function that will inform the menu manager whether to invoke
  12291.          the selection in the menu.
  12292.  
  12293.          Example d) Informs the menu manager to hide the menu window
  12294.          when a menu function is invoked.
  12295.  
  12296.          Example e) Informs the menu manager not to hide the menu when
  12297.          control is returned to the function that called
  12298.          PopupSelectMenu().
  12299.  
  12300.          Example f) Informs the menu manager to process unavailable
  12301.          entries.  This is useful if you want to set up your own error
  12302.          routine if the user selects an unavailable entry.
  12303.  
  12304.  
  12305.  
  12306.  
  12307.          Page 191          The C Window Library               Page 191
  12308.  
  12309.          Example g) imforms the menu manager to distinguish between
  12310.          normal keys and enhanced keys.
  12311.  
  12312.  
  12313.          Setting Multiple Options
  12314.          ------------------------
  12315.          You can also set multiple options with a single call by using
  12316.          a bitwise OR (|).  For example:
  12317.  
  12318.          PopupSetOptions(p,POPUPWRAP | POPUPSTATIC | POPUPCONFIRM,1)
  12319.  
  12320.          will set options POPUPWRAP, POPUPSTATIC, and POPUPCONFIRM
  12321.          defined above.
  12322.  
  12323.  
  12324.  
  12325.          Setting the PopupSetConfirmFunction()
  12326.          -------------------------------------
  12327.  
  12328.          When using the POPUPCONFIRM option, you must also use the
  12329.          PopupSetConfirmFunction() function to point the menu to the
  12330.          confirmation function that will be called when a hotkey is
  12331.          pressed.  Here is a prototype of the
  12332.          PopupSetConfirmFunction():
  12333.  
  12334.          PopupSetConfirmFunction(POPUP_MENU_PTR p, int (*func)())
  12335.  
  12336.          where p is the desired popup menu to assign the confirmation
  12337.          function to, and func is a pointer to a function that will
  12338.          return a value back to the menu manager that will inform it
  12339.          to either invoke the option, or ignore the option.
  12340.  
  12341.          When the confirmation function is called, the menu manager
  12342.          passes three arguments to func.  The prototype for your user
  12343.          defined function should be as follows:
  12344.  
  12345.          int my_confirm_func(POPUP_MENU_PTR p, unsigned key,
  12346.                              unsigned sel)
  12347.  
  12348.          where p is the POPUP_MENU_PTR that is currently being
  12349.          processed, key is the hotkey that was pressed, and sel is the
  12350.          selection where the highlight bar is now positioned.  The
  12351.          highlight bar is always positioned on the hotkey selection
  12352.          even if it may not be invoked.  This user defined function
  12353.          must return a value back to the menu manager.  The valid
  12354.          values that can be returned are POPUP_CONTINUE and
  12355.          POPUP_DO_CHOICE.  If POPUP_CONTINUE is returned, the menu
  12356.          selection is not invoked, if POPUP_DO_CHOICE is selected, the
  12357.          menu entry is invoked.  Here is an example:
  12358.  
  12359.             #include "menu.h"
  12360.  
  12361.             int my_confirm_func();
  12362.             POPUP_MENU_PTR p;
  12363.  
  12364.  
  12365.  
  12366.  
  12367.          Page 192          The C Window Library               Page 192
  12368.  
  12369.             /* ... */
  12370.             main()
  12371.             {
  12372.               PopupSetOptions(p,POPUPCONFIRM,1);
  12373.               PopupSetConfirmFunction(p,my_confirm_func);
  12374.               /* ... */
  12375.             }
  12376.  
  12377.             my_confirm_func(POPUP_MENU_PTR p, unsigned k, unsigned sel)
  12378.             {
  12379.               /* ... */
  12380.               if (k == 'C' || k == 'c' || k == ALTF)
  12381.                 return POPUP_CONTINUE;
  12382.               else
  12383.                 return POPUP_DO_CHOICE;
  12384.             }
  12385.  
  12386.          The above function invokes the menu selection if the hotkey
  12387.          that was pressed is not a 'C', 'c', or ALT-F.
  12388.  
  12389.          The confirmation function can do anything, including setting
  12390.          options in the popup menu, displaying other windows etc.
  12391.  
  12392.  
  12393.  
  12394.          Return Values for PopupSetOptions() function
  12395.          --------------------------------------------
  12396.  
  12397.          You can use the PopupSetOptions() function at any time,
  12398.          including before calling the PopupSelectMenu() function.  If
  12399.          the option is not a valid option, the function returns
  12400.          NO_ERROR, but does not change anything.  If the switch is not
  12401.          0 or 1, a 1 is assumed.
  12402.  
  12403.          If there is an error, the error conditions and reasons are
  12404.          the same as the PopupSelectMenu() function defined above.
  12405.  
  12406.  
  12407.  
  12408.  
  12409.  
  12410.  
  12411.  
  12412.  
  12413.  
  12414.  
  12415.  
  12416.  
  12417.  
  12418.  
  12419.  
  12420.  
  12421.  
  12422.  
  12423.  
  12424.  
  12425.  
  12426.  
  12427.          Page 193          The C Window Library               Page 193
  12428.  
  12429.             MAKING MENU ENTRIES AVAILABLE AND UNAVAILABLE
  12430.             ---------------------------------------------
  12431.  
  12432.          There may be cases when a menu entry should be made
  12433.          unavailable.  The entry shows up in the menu, but it is a
  12434.          different color than the other entries, and the highlight bar
  12435.          will just skip over this unavailable entry.
  12436.  
  12437.  
  12438.  
  12439.          PopupMakeEntryAvailable() and
  12440.          PopupMakeEntryUnavailable() functions
  12441.          -------------------------------------
  12442.  
  12443.          With The C Window Library, you can make entries available and
  12444.          unavailable at any time.  The PopupMakeEntryAvailable() and
  12445.          the PopupMakeEntryUnavailable() functions perform these
  12446.          tasks.
  12447.  
  12448.          A prototype of the call to both of these functions is as
  12449.          follows:
  12450.  
  12451.          int PopupMakeEntryAvailable(POPUP_MENU_PTR p, unsigned entry)
  12452.  
  12453.          int PopupMakeEntryUnavailable(POPUP_MENU_PTR p,
  12454.                                        unsigned entry)
  12455.  
  12456.          The first argument is the POPUP_MENU_PTR.  The second
  12457.          argument is the number of the entry that you wish to change.
  12458.          Entry numbers range from 1 to the highest entry in the menu.
  12459.  
  12460.  
  12461.  
  12462.          POPUPOVERRIDE option
  12463.          --------------------
  12464.  
  12465.          If the POPUPOVERRIDE option is set (see above), the menu
  12466.          manager will still process unavailable entries.  You must
  12467.          turn off POPUPOVERRIDE by using the PopupSetOptions()
  12468.          function if you do not want to process unavailable entries.
  12469.  
  12470.  
  12471.  
  12472.          Return Values for PopupMakeEntryAvaialble() and
  12473.          PopupMakeEntryUnavailable() functions
  12474.          -----------------------------------------------
  12475.  
  12476.          If there is no error, both of these functions return
  12477.          NO_ERROR.  If there is an error, the following possibilities
  12478.          can occur:
  12479.  
  12480.          1) The error can be one of the errors defined above for the
  12481.             PopupSelectMenu().
  12482.  
  12483.          2) The menu entry is invalid.
  12484.  
  12485.  
  12486.  
  12487.          Page 194          The C Window Library               Page 194
  12488.  
  12489.          Refer to the PopupSelectMenu() return values and reasons for
  12490.          failure defined above for error condition 1).  If the error
  12491.          is 2), check to see if the entry number supplied is valid.
  12492.          The entry number cannot be < 1 or greater than the number of
  12493.          selections in the popup menu.
  12494.  
  12495.  
  12496.          If error 2) has occurred, the PopupMakeEntryAvailable() and
  12497.          the PopupMakeEntryUnavailable() return MENU_ENTRY_INVALID.
  12498.  
  12499.  
  12500.  
  12501.  
  12502.  
  12503.  
  12504.  
  12505.  
  12506.  
  12507.  
  12508.  
  12509.  
  12510.  
  12511.  
  12512.  
  12513.  
  12514.  
  12515.  
  12516.  
  12517.  
  12518.  
  12519.  
  12520.  
  12521.  
  12522.  
  12523.  
  12524.  
  12525.  
  12526.  
  12527.  
  12528.  
  12529.  
  12530.  
  12531.  
  12532.  
  12533.  
  12534.  
  12535.  
  12536.  
  12537.  
  12538.  
  12539.  
  12540.  
  12541.  
  12542.  
  12543.  
  12544.  
  12545.  
  12546.  
  12547.          Page 195          The C Window Library               Page 195
  12548.  
  12549.                    CHANGING THE MENU ENTRY STRINGS
  12550.                    -------------------------------
  12551.  
  12552.          There may be times when you want to change a POPUP_MENU_ENTRY
  12553.          entry_name string.  For instance, you may have a menu entry
  12554.          with the following entry_name:
  12555.  
  12556.                  "Default File Name     ABC.DAT"
  12557.  
  12558.  
  12559.          If the user selects this choice, the file name should change
  12560.          to another file name the user wants.  From there the menu
  12561.          should reflect the new choice the user has made.  Let's say
  12562.          the user has changed the default file name to DEF.DAT.  The
  12563.          menu then should say:
  12564.  
  12565.                  "Default File Name     DEF.DAT"
  12566.  
  12567.  
  12568.  
  12569.          PopupChangeEntryString() function
  12570.          ---------------------------------
  12571.  
  12572.          How do you change the entry string?  One way is to fool
  12573.          around with the POPUP_MENU_PTR's structure members, and
  12574.          change the string yourself.  This is not recommended for the
  12575.          novice to average C programmer, since it is not a good idea
  12576.          to change the structure members directly without a full
  12577.          understanding of the structure.
  12578.  
  12579.          A safer way is to call the PopupChangeEntryString() function.
  12580.          A prototype of this function is as follows:
  12581.  
  12582.          PopupChangeEntryString(POPUP_MENU_PTR p, unsigned entry,
  12583.                                 char *newstring)
  12584.  
  12585.          The first argument is the POPUP_MENU_PTR.  The second
  12586.          argument is the number of the entry that you wish to change.
  12587.          Entry numbers range from 1 to the highest entry in the menu.
  12588.          The third argument is a pointer to the new character string.
  12589.          The newstring cannot be longer than the current
  12590.          POPUP_MENU_ENTRY entry_name string.
  12591.  
  12592.  
  12593.  
  12594.  
  12595.          Return Values for PopupChangeEntryString() function
  12596.          ---------------------------------------------------
  12597.  
  12598.          If there is no error, NO_ERROR is returned.
  12599.  
  12600.          If there is an error, the error conditions and reasons are
  12601.          the same as the PopupMakeEntryAvailable() function defined
  12602.          above.
  12603.  
  12604.  
  12605.  
  12606.  
  12607.          Page 196          The C Window Library               Page 196
  12608.  
  12609.                         REDEFINING MENU KEYS
  12610.                         --------------------
  12611.  
  12612.  
  12613.          Setting Global Key Definitions and
  12614.          the popup_key_definition Array
  12615.          ----------------------------------
  12616.  
  12617.          You can redefine the keys used to control moving the
  12618.          highlight bar, accepting the menu choice, and exiting from
  12619.          the menu.  Here is a list of the default key mapping:
  12620.  
  12621.             Function                      Key             Constant
  12622.             --------                      ---              ------
  12623.           Move highlight bar up       Up Arrow   POPUP_UPKEY
  12624.           Move highlight bar down     Down Arrow POPUP_DOWNKEY
  12625.           Accept Menu Choice          Enter      POPUP_ACCEPTKEY
  12626.           Escape Pop-up menu          Escape     POPUP_QUITKEY
  12627.           Move To First Menu Item     Home       POPUP_HOMEKEY
  12628.           Move to Last Menu Item      End        POPUP_ENDKEY
  12629.           Scroll entries up by one
  12630.           page                        PgUp       POPUP_PAGEUPKEY
  12631.           Scroll entries down by one
  12632.           page                        PgDn       POPUP_PAGEDOWNKEY
  12633.          *Move To Next Popup Menu     Unassigned POPUP_RIGHTKEY
  12634.          *Move to Previous Popup Menu Unassigned POPUP_LEFTKEY
  12635.          *Escape Pulldown Menu        Unassigned POPUP_PULLDOWN_QUITKEY
  12636.  
  12637.          The global array popup_key_definition contains the values of
  12638.          the default popup menu key definitions.  The names under the
  12639.          Constant heading are the offsets in the popup_key_definition
  12640.          array of where the key value for the function is defined.
  12641.          For instance, the value for the "Move highlight bar up"
  12642.          function is located at popup_key_definition[POPUP_UPKEY].
  12643.          You can change the values in popup_key_definition at any
  12644.          time, but make sure that a definition for "Escape Pop-up
  12645.          menu" always exists, and that there are no duplicate
  12646.          definitions (i.e.  the "Move highlight bar up" key definition
  12647.          is the same as the "Move highlight bar down" key definition).
  12648.          When defining new key values, you should use the values
  12649.          defined in the keycodes.h header file for non-ascii keys.
  12650.  
  12651.          * The POPUP_RIGHTKEY, POPUP_LEFTKEY, and the
  12652.            POPUP_PULLDOWN_QUITKEY definitions only apply to popup
  12653.            menus that are incorporated in a pulldown menu.  See the
  12654.            section on pulldown menus for more information.
  12655.  
  12656.  
  12657.  
  12658.          Setting Local Key Definitions
  12659.          -----------------------------
  12660.  
  12661.          Another way of redefining menu keys is to load your own array
  12662.          of key definitions with your desired values, and then calling
  12663.          the PopupAssignKeys() function.  With this method, each menu
  12664.          can have different key definitions.
  12665.  
  12666.  
  12667.          Page 197          The C Window Library               Page 197
  12668.  
  12669.          PopupAssignKeys() function
  12670.          --------------------------
  12671.  
  12672.          Here is a prototype of the PopupAssignKeys() function:
  12673.  
  12674.          int PopupAssignKeys(POPUP_MENU_PTR p, unsigned *keys)
  12675.  
  12676.          where p is the POPUP_MENU_PTR, and keys is an array of key
  12677.          definitions.  Here is a small code example:
  12678.  
  12679.  
  12680.          #include "menu.h"
  12681.  
  12682.          unsigned mykeys[NUMPOPUPKEYS] = {CTRLU,CTRLD,RETURN,
  12683.                                         ESC,HOME,END,0,0,0,0};
  12684.          POPUP_MENU_PTR p;
  12685.  
  12686.          /* Other stuff...*/
  12687.  
  12688.          main()
  12689.          {
  12690.            /* Assume p is initialized */
  12691.  
  12692.            /* Assigns my key definitions to popup menu p */
  12693.            PopupAssignKeys(p,mykeys);
  12694.          }
  12695.  
  12696.          The constant NUMPOPUPKEYS should be used to make sure that
  12697.          your array of key definitions is large enough to hold all the
  12698.          definitions.   The above example uses the constants defined
  12699.          in keycodes.h to assign to the array mykeys.  Each position
  12700.          in the mykeys array uses the default key mapping explained
  12701.          above.  In other words, mykeys[POPUP_UPKEY] is CTRLU, etc.
  12702.  
  12703.  
  12704.  
  12705.          Return Values for PopupAssignKeys() function
  12706.          --------------------------------------------
  12707.  
  12708.          If there is no error, then NO_ERROR is returned.
  12709.  
  12710.          If there is an error, the error conditions and reasons are
  12711.          the same as the PopupSelectMenu() function defined above.
  12712.  
  12713.  
  12714.  
  12715.  
  12716.  
  12717.  
  12718.  
  12719.  
  12720.  
  12721.  
  12722.  
  12723.  
  12724.  
  12725.  
  12726.  
  12727.          Page 198          The C Window Library               Page 198
  12728.  
  12729.                       PROCESSING UNDEFINED KEYS
  12730.                       -------------------------
  12731.  
  12732.          If you are an advanced programmer and/or have experience in
  12733.          using other window/menu libraries, you may be wondering "how
  12734.          do I define a function that supplies context-sensitive help
  12735.          for each POPUP_MENU_ENTRY?  There is no structure member in
  12736.          POPUP_MENU_ENTRY that supplies this".  With The C Window
  12737.          Library, any key that is not recognized by the menu manager
  12738.          (i.e. the key struck does not invoke a menu option, move the
  12739.          highlight bar up or down, or ends processing of the menu) can
  12740.          be processed by calling a user written function.   The
  12741.          WindowGet...() family of functions allowed us to define a
  12742.          function that will be called if a key that has no current
  12743.          definition is pressed.  For popup menus, we can do the same
  12744.          thing.
  12745.  
  12746.  
  12747.          The popup_undef_key function pointer
  12748.          ------------------------------------
  12749.  
  12750.          The global function pointer, popup_undef_key, can point to a
  12751.          user written function that will be called when the menu
  12752.          manager encounters a key that is not defined.  The
  12753.          declaration for popup_undef_key is as follows:
  12754.  
  12755.          unsigned int (*popup_undef_key)(POPUP_MENU_PTR p,
  12756.                                          unsigned int sel,
  12757.                                          unsigned int *choice)
  12758.  
  12759.          The user written function takes three arguments.  The first
  12760.          argument is a pointer to the popup menu that the menu manager
  12761.          is currently processing. The second argument is an integer
  12762.          that contains the value of the key that was pressed.  The
  12763.          third argument is a pointer to an integer that will contain
  12764.          the number of the menu choice to execute.  Initially, choice
  12765.          points to an integer that contains the current menu choice
  12766.          that the menu highlight bar is situated.  For instance, if
  12767.          the highlight bar is on the first menu choice when an
  12768.          undefined key is pressed, *choice will be equal to 1.  If
  12769.          popup_undef_key is equal to a Null Function pointer (NULLFN),
  12770.          no user defined function is called.  By default,
  12771.          popup_undef_key is assigned to NULLFN.
  12772.  
  12773.  
  12774.          Values returned to menu manager
  12775.          -------------------------------
  12776.  
  12777.          If popup_undef_key is assigned to a function, the function
  12778.          must return an integer back to the menu manager.  This
  12779.          integer value will tell the menu manager how to proceed.
  12780.          Here is a list of the valid return values that the user
  12781.          written function can return:
  12782.  
  12783.  
  12784.  
  12785.  
  12786.  
  12787.          Page 199          The C Window Library               Page 199
  12788.  
  12789.            Return                         Action to
  12790.            Value                            Take
  12791.            ------                         ---------
  12792.  
  12793.           POPUP_CONTINUE          No Action. Continue processing the
  12794.                                   popup menu.
  12795.  
  12796.           POPUP_MOVE_UP           Move the highlight bar up.
  12797.  
  12798.           POPUP_MOVE_DOWN         Move the highlight bar down.
  12799.  
  12800.           POPUP_DO_CHOICE         Accept and invoke menu entry
  12801.                                   assigned to *choice.
  12802.  
  12803.           POPUP_MOVE_CONTINUE     Move the highlight bar to menu entry
  12804.                                   assigned to *choice and continue
  12805.                                   processing menu.
  12806.  
  12807.           POPUP_ESCAPE            Escape the popup menu.
  12808.  
  12809.           POPUP_MOVE_HOME         Move highlight to first available
  12810.                                   menu entry.
  12811.  
  12812.           POPUP_MOVE_END          Move highlight to last available
  12813.                                   menu entry.
  12814.  
  12815.           POPUP_MOVE_PAGEUP       Scroll the entries in the popup
  12816.                                   window up by one "page" (a page is
  12817.                                   the current height of the popup
  12818.                                   window).
  12819.  
  12820.           POPUP_MOVE_PAGEDOWN     Scroll the entries in the popup
  12821.                                   window down by one "page" (a page is
  12822.                                   the current height of the popup
  12823.                                   window).
  12824.  
  12825.          *POPUP_MOVE_LEFT         Move to next popup menu.
  12826.  
  12827.          *POPUP_MOVE_RIGHT        Move to previous popup menu.
  12828.  
  12829.          *POPUP_PULLDOWN_QUIT     Escape pulldown menu
  12830.  
  12831.          A return value of POPUP_CONTINUE is a "do nothing" command to
  12832.          the menu manager.
  12833.  
  12834.          If POPUP_DO_CHOICE is returned to the menu manager, the
  12835.          integer assigned to the parameter *choice is used as the menu
  12836.          entry to invoke.  The highlight bar will automatically be
  12837.          moved to the menu choice specified, and the menu function
  12838.          will be called.  If POPUP_MOVE_CONTINUE is returned to the
  12839.          menu manager, the highlight bar will be moved to the entry
  12840.          specified by the value of *choice, but no function is called.
  12841.  
  12842.          Return values of POPUP_DO_CHOICE and POPUP_MOVE_CONTINUE only
  12843.          work when the menu entry specified by *choice is an available
  12844.  
  12845.  
  12846.  
  12847.          Page 200          The C Window Library               Page 200
  12848.  
  12849.          entry or the POPUPVERRIDE option is on , otherwise the menu
  12850.          manager just continues processing the popup menu.
  12851.  
  12852.  
  12853.          * The POPUP_MOVE_RIGHT, POPUP_MOVE_LEFT, and
  12854.            POPUP_PULLDOWN_QUIT only apply to popup menus that are
  12855.            incorporated in a pulldown menu system.  See the section on
  12856.            pulldown menus for more information.
  12857.  
  12858.          Here is an example of using a user defined function for the
  12859.          undefined keys:
  12860.  
  12861.          #include "menu.h"
  12862.  
  12863.          /*  Other includes */
  12864.  
  12865.          int user_func();
  12866.  
  12867.          main()
  12868.  
  12869.          {
  12870.            popup_undef_key = user_func;
  12871.  
  12872.            /* Other code */
  12873.          }
  12874.  
  12875.          unsigned int user_func(POPUP_MENU_PTR p, unsigned sel,
  12876.                                 unsigned *choice)
  12877.          {
  12878.            switch(sel)
  12879.  
  12880.            {
  12881.              case F1:
  12882.                help(*choice);         /* call help function */
  12883.                return POPUP_CONTINUE; /* return "do nothing" */
  12884.              case F2:
  12885.                *choice = 6;  /* let menu manager know to do
  12886.                                 choice 6 on the menu */
  12887.                return POPUP_DO_CHOICE;  /* Also let menu manager
  12888.                                            know we are returning the
  12889.                                            "do the function assigned to
  12890.                                             *choice" command */
  12891.              default:
  12892.                return POPUP_CONTINUE;
  12893.                /* let menu manager know not to do anything */
  12894.            }
  12895.          }
  12896.  
  12897.          int help(int choice)
  12898.          {  /* help function */
  12899.            switch (choice)
  12900.            {
  12901.              case 1:
  12902.                /* do context-sensitive help for entry 1 */
  12903.              break;
  12904.  
  12905.  
  12906.  
  12907.          Page 201          The C Window Library               Page 201
  12908.  
  12909.              case 2:
  12910.                /* do context-sensitive help for entry 2 */
  12911.              break;
  12912.               /* do more entries */
  12913.               /* ... */
  12914.            }
  12915.          }
  12916.  
  12917.          In the above example, if the user hits F1, a help function is
  12918.          called.  If you wanted to know how to incorporate a help
  12919.          function in the popup menus, here is the way to do it.
  12920.  
  12921.          If the user hits F2, the integer pointed to by choice is
  12922.          assigned a 6, and user_func() returns POPUP_DO_CHOICE to the
  12923.          menu manager.  This tells the menu manager to invoke the
  12924.          function assigned to menu entry 6.
  12925.  
  12926.  
  12927.  
  12928.  
  12929.  
  12930.  
  12931.  
  12932.  
  12933.  
  12934.  
  12935.  
  12936.  
  12937.  
  12938.  
  12939.  
  12940.  
  12941.  
  12942.  
  12943.  
  12944.  
  12945.  
  12946.  
  12947.  
  12948.  
  12949.  
  12950.  
  12951.  
  12952.  
  12953.  
  12954.  
  12955.  
  12956.  
  12957.  
  12958.  
  12959.  
  12960.  
  12961.  
  12962.  
  12963.  
  12964.  
  12965.  
  12966.  
  12967.          Page 202          The C Window Library               Page 202
  12968.  
  12969.                          PRE-INPUT FUNCTION
  12970.                          ------------------
  12971.  
  12972.          With The C Window Library, you can define a function that
  12973.          will be performed just before the menu manager waits for the
  12974.          user to enter a keystroke.  This function can perform just
  12975.          about anything.
  12976.  
  12977.  
  12978.          Setting the global_popup_prefunc function pointer
  12979.          -------------------------------------------------
  12980.  
  12981.          The global_popup_prefunc function pointer points to this user
  12982.          written function.  Here is the prototype:
  12983.  
  12984.          int (*global_popup_prefunc)(POPUP_MENU_PTR p, unsigned *sel)
  12985.  
  12986.          The arguments that will be passed to your function are the
  12987.          following:
  12988.  
  12989.          a)  The POPUP_MENU_PTR of the popup menu that called your
  12990.              function, and
  12991.  
  12992.          b)  A pointer to the number of the selection that the
  12993.              highlight bar is currently on.
  12994.  
  12995.          The selection number ranges from 1 to the highest entry
  12996.          number of the menu.
  12997.  
  12998.          The pre-input function MUST return a value back to the menu
  12999.          manager.  The return values that can be returned are the same
  13000.          as the popup_undef_key function described above.  If you are
  13001.          using a version of The C Window Library prior to version 1.5,
  13002.          you must declare your pre-input function as returning an int,
  13003.          and you must return a value back to the menu manager.
  13004.          Versions prior to 1.5 declared the pre-input function as
  13005.          void.
  13006.  
  13007.          The POPUP_DO_CHOICE and POPUP_MOVE_CONTINUE return values
  13008.          will move the highlight bar to the entry number that is
  13009.          assigned to the *sel argument when the pre-input function has
  13010.          returned.
  13011.  
  13012.          By default, global_popup_prefunc points to a NULLFN, and
  13013.          therefore will not be performed.  However, you can implement
  13014.          pre-input functions depending on the current selection.  For
  13015.          instance, you can write a function that displays extra
  13016.          information for each entry like so:
  13017.  
  13018.          #include "menu.h"
  13019.  
  13020.          char *mess[] = {
  13021.                 " This option saves and loads files",
  13022.                 " This brings you in edit mode",
  13023.                 " This compiles and/or links the current program",
  13024.  
  13025.  
  13026.  
  13027.          Page 203          The C Window Library               Page 203
  13028.  
  13029.                /* ... More stuff */
  13030.                         };
  13031.  
  13032.          WPOINTER message_window;
  13033.  
  13034.          int disp_info();
  13035.  
  13036.          main()
  13037.          {
  13038.            /* ... */
  13039.  
  13040.            global_popup_prefunc = disp_info;
  13041.  
  13042.            /* ... */
  13043.          }
  13044.  
  13045.          int disp_info(POPUP_MENU_PTR p, unsigned *sel)
  13046.          {
  13047.             /* Assume message_window already created and opened */
  13048.  
  13049.            WindowClear(message_window,
  13050.                        CREATE_VIDEO_ATTRIBUTE(black,white));
  13051.            WindowWriteString(message_window,mess[*sel-1],1,1);
  13052.            return POPUP_CONTINUE;
  13053.          }
  13054.  
  13055.  
  13056.          For simplicity, the menu definitions are left out of the
  13057.          preceding code sample.  The disp_info displays the
  13058.          appropriate description in the window message_window.
  13059.          POPUP_CONTINUE is returned to the menu manager.  This informs
  13060.          the menu manager to continue looking for a keystroke.
  13061.  
  13062.  
  13063.  
  13064.  
  13065.  
  13066.  
  13067.  
  13068.  
  13069.  
  13070.  
  13071.  
  13072.  
  13073.  
  13074.  
  13075.  
  13076.  
  13077.  
  13078.  
  13079.  
  13080.  
  13081.  
  13082.  
  13083.  
  13084.  
  13085.  
  13086.  
  13087.          Page 204          The C Window Library               Page 204
  13088.  
  13089.                       DISPOSING OF POPUP MENUS
  13090.                       ------------------------
  13091.  
  13092.  
  13093.          PopupMenuFree()
  13094.          ---------------
  13095.  
  13096.          If the popup menu is no longer needed, the PopupMenuFree()
  13097.          function will dispose of the popup menu and return any memory
  13098.          allocated to the popup menu, window, and virtual window
  13099.          memory back to the heap.  The call to the function is very
  13100.          simple:
  13101.  
  13102.                 PopupMenuFree(POPUP_MENU_PTR p)
  13103.  
  13104.          where p is the POPUP_MENU_PTR to dispose of.  Since this
  13105.          function destroys the POPUP_MENU_PTR p, p must not be used
  13106.          for any popup menu functions, unless p is pointing to a valid
  13107.          POPUP_MENU_PTR.
  13108.  
  13109.  
  13110.  
  13111.          Return Values for PopupMenuFree()
  13112.          ---------------------------------
  13113.  
  13114.          The return values and the reasons for failure are the same as
  13115.          PopupSelectMenu().
  13116.  
  13117.  
  13118.  
  13119.  
  13120.  
  13121.  
  13122.  
  13123.  
  13124.  
  13125.  
  13126.  
  13127.  
  13128.  
  13129.  
  13130.  
  13131.  
  13132.  
  13133.  
  13134.  
  13135.  
  13136.  
  13137.  
  13138.  
  13139.  
  13140.  
  13141.  
  13142.  
  13143.  
  13144.  
  13145.  
  13146.  
  13147.          Page 205          The C Window Library               Page 205
  13148.  
  13149.                               BAR MENUS
  13150.                               ---------
  13151.  
  13152.          Description
  13153.          -----------
  13154.  
  13155.          A bar menu is a horizontal menu with a list of entries that
  13156.          are selected by placing a highlight bar on the option and
  13157.          pressing return, or by invoking the function by using a
  13158.          hotkey.  Bar menus can span several lines. In other words,
  13159.          menu entries do not have to fit on a single line.
  13160.  
  13161.  
  13162.          Here is a partial list of the various options you can have
  13163.          with bar menus:
  13164.  
  13165.             * Highlight bar wrapping - wrap highlight bar to first or
  13166.                                        last option when there are no
  13167.                                        more selections.
  13168.  
  13169.             * Static Menus           - menu remains on the screen when
  13170.                                        entry is selected.
  13171.  
  13172.             * Perpetual Menus        - menu remain on the screen
  13173.                                        regardless of whether the
  13174.                                        BarSelectMenu() function
  13175.                                        (explained later) is called or
  13176.                                        not.
  13177.  
  13178.             * Hidden (Unavailable) entries - You can make an entry in
  13179.                                              the bar menu unavailable
  13180.                                              or available at any time.
  13181.  
  13182.             * Color scheme of the menu - You can customize the color
  13183.                                          of the highlight bar, the
  13184.                                          hotkey letters, hidden
  13185.                                          entries, etc.
  13186.  
  13187.             * Change entry names       - You can safely change the
  13188.                                          names displayed in the menu
  13189.                                          at any time.
  13190.  
  13191.             * Use a mouse to select menu entries.
  13192.  
  13193.  
  13194.  
  13195.  
  13196.          Windows and Virtual Windows
  13197.          ---------------------------
  13198.  
  13199.          Unlike popup menus, bar menus do not use virtual windows.
  13200.          Only normal text windows are used.
  13201.  
  13202.  
  13203.  
  13204.  
  13205.  
  13206.  
  13207.          Page 206          The C Window Library               Page 206
  13208.  
  13209.                          CREATING BAR MENUS
  13210.                          ------------------
  13211.  
  13212.  
  13213.  
  13214.          The BAR_MENU_ENTRY structure
  13215.          ----------------------------
  13216.  
  13217.          The two most important parts of the bar menu are the
  13218.          BAR_MENU_ENTRY structure and the BAR_MENU_PTR structure.  The
  13219.          BAR_MENU_ENTRY structure is the first step in creating a bar
  13220.          menu and is discussed here.
  13221.  
  13222.          Each entry in the bar menu has its own BAR_MENU_ENTRY
  13223.          structure associated with it.  The layout of this structure
  13224.          is as follows:
  13225.  
  13226.  
  13227.          char     *entry_name     -- This is the string that is
  13228.                                      displayed in the bar window.
  13229.  
  13230.          unsigned  row            -- Row in the window to display
  13231.                                      entry_name.
  13232.  
  13233.          char      hotkey_letter  -- This is a character in entry_name
  13234.                                      that is highlighted from the rest
  13235.                                      of the characters in entry_name.
  13236.                                      This letter will automatically
  13237.                                      invoke the menu function
  13238.                                      associated with entry_name.
  13239.  
  13240.          unsigned  ext_hotkey     -- This is a secondary hotkey.  The
  13241.                                      difference between hotkey_letter
  13242.                                      and ext_hotkey is that ext_hotkey
  13243.                                      can handle keys that are not
  13244.                                      ASCII keys (the F keys, Alt and
  13245.                                      Ctrl key combinations, etc.).
  13246.  
  13247.          int (*func)()            -- Pointer to function that is
  13248.                                      invoked when option is selected.
  13249.  
  13250.  
  13251.          An array of BAR_MENU_ENTRY's are needed to create all of the
  13252.          entries on the bar menu.  The order of the array elements
  13253.          determine the order of how they are placed in the  window.  A
  13254.          code sample to create an array of BAR_MENU_ENTRY's would be
  13255.          as follows:
  13256.  
  13257.          #include "menu.h"
  13258.          int menu_func();
  13259.  
  13260.          BAR_MENU_ENTRY bar_items[] = {
  13261.               "File",    /* option name */
  13262.                1,        /* row in window to display option name */
  13263.                4,        /* col. in window to display option */
  13264.  
  13265.  
  13266.  
  13267.          Page 207          The C Window Library               Page 207
  13268.  
  13269.               'F',       /* hotkey letter */
  13270.               ALTF,      /* secondary hotkey */
  13271.               rt2,       /* function to do if chosen */ ,
  13272.  
  13273.                /* Now define the rest of the BAR_MENU_ENTRY's */
  13274.                "Edit",1,10,'E',0,menu_func,
  13275.                "Run",1,17,'R',0,menu_func,
  13276.                "Compile",1,23,'C',0,menu_func,
  13277.                "Project",1,33,'P',0,menu_func,
  13278.                "Options",1,43,'O',0,menu_func,
  13279.                "Debug",1,53,'D',0,menu_func,
  13280.                "Break/watch",1,61,'B',0,menu_func,
  13281.  
  13282.                /* Now terminate with a CWL_NULL option_name */
  13283.                 CWL_NULL};
  13284.  
  13285.  
  13286.          The first include file, menu.h, is must be included in each
  13287.          source file that calls menu functions.
  13288.  
  13289.          As you can see, there is an array of BAR_MENU_ENTRY's, namely
  13290.          bar_items.  Each entry consists of an entry name, row number,
  13291.          column number, hotkey letter, secondary hotkey, and a
  13292.          function to call when the entry is selected.  The list of
  13293.          BAR_MENU_ENTRY's MUST be terminated by a CWL_NULL entry name.
  13294.  
  13295.          There is an alternate method of creating the BAR_MENU_ENTRY
  13296.          array.  Later on, we will discuss creating these entries
  13297.          dynamically.
  13298.  
  13299.  
  13300.  
  13301.          Defining Hotkeys
  13302.          ----------------
  13303.  
  13304.          The hotkey_letter defined in the BAR_MENU_ENTRY structure
  13305.          must match one of the letters in its corresponding
  13306.          entry_name.  For example, "File", has the hotkey_letter
  13307.          defined as 'F'.  Since 'F' matches the first letter in
  13308.          "File", the first 'F' in "File" is highlighted.  If there is
  13309.          no match, or if the hotkey_letter is 0, there is no hotkey
  13310.          associated with this entry.  When the menu is displayed,
  13311.          either the 'f' or 'F' will be accepted as a valid selection
  13312.          to the entry "File".   If there is a BAR_MENU_ENTRY with the
  13313.          same hotkey letter as another BAR_MENU_ENTRY, the
  13314.          BAR_MENU_ENTRY closest to the first entry is chosen.
  13315.  
  13316.  
  13317.  
  13318.  
  13319.  
  13320.  
  13321.  
  13322.  
  13323.  
  13324.  
  13325.  
  13326.  
  13327.          Page 208          The C Window Library               Page 208
  13328.  
  13329.          The ext_hotkey is used if the hotkey cannot be defined as a
  13330.          single character, or if you want another hotkey definition.
  13331.          In the above example, the "File" entry_name has an ext_hotkey
  13332.          of ALTF3 (defined in keycodes.h).  If the ALT-F3 key is
  13333.          pressed, the function rt2() is automatically invoked.  If the
  13334.          ext_hotkey letter is 0, there is no ext_hotkey defined.  If
  13335.          there is a BAR_MENU_ENTRY with the same ext_hotkey as another
  13336.          BAR_MENU_ENTRY, the BAR_MENU_ENTRY closest to the first entry
  13337.          is chosen.
  13338.  
  13339.  
  13340.  
  13341.          Assigning the function to perform
  13342.          ---------------------------------
  13343.  
  13344.          The func() member is the function that is performed when its
  13345.          corresponding entry_name is chosen.
  13346.  
  13347.  
  13348.          This is the first step in completing the total bar menu.
  13349.          Once the array of BAR_MENU_ENTRY's is created the next step
  13350.          is to define the colors for each element of the bar menu.
  13351.  
  13352.  
  13353.  
  13354.          Coloring Bar Menus
  13355.          ------------------
  13356.  
  13357.          An array of unsigned integers is used to define the color
  13358.          scheme of the bar menu.  Each element of this array stands
  13359.          for a certain area of the bar menu.  Here is a list of array
  13360.          positions and what they stand for.
  13361.  
  13362.  
  13363.          Position
  13364.          Constant
  13365.          --------
  13366.  
  13367.          ENTRYCOLOR    --  color of the text area of the window.
  13368.  
  13369.          BORDERCOLOR    --  color of the border of the window.
  13370.  
  13371.          HOTKEYCOLOR    --  color of the hotkey letter.
  13372.  
  13373.          HIGHLIGHTCOLOR --  color of the highlight bar.
  13374.  
  13375.          UNAVAILCOLOR   --  color of the unavailable entries.
  13376.  
  13377.          Position ENTRYCOLOR of the array defines the color of the
  13378.          text area of the viewport window.  This in turn defines the
  13379.          color of each entry_name of all of the BAR_MENU_ENTRY's.
  13380.  
  13381.          Position BORDERCOLOR defines the color of the border of the
  13382.          window.  If the window does not have a border, this attribute
  13383.          is ignored.
  13384.  
  13385.  
  13386.  
  13387.          Page 209          The C Window Library               Page 209
  13388.  
  13389.          Position HOTKEYCOLOR defines the color to use for the hotkey
  13390.          letter.  In the above example, the 'L', 'P', 'N', etc. of
  13391.          each respective entry_name is displayed using this color.
  13392.  
  13393.          Position HIGHLIGHTCOLOR defines the color used for the
  13394.          highlight bar.  This bar is moved up and down when the user
  13395.          is making a selection.
  13396.  
  13397.          Position UNAVAILCOLOR defines the color of the unavailable
  13398.          menu entries.  Whenever a menu entry is unavailable, the
  13399.          entry_name string displayed takes on this color.
  13400.  
  13401.          Colors can be created by using the CREATE_VIDEO_ATTRIBUTE()
  13402.          macro.   A code sample to create the colors is as follows:
  13403.  
  13404.  
  13405.          #include "menu.h"
  13406.          unsigned int menu_colors[5];
  13407.  
  13408.          main()
  13409.          {
  13410.            {... code ...}
  13411.            menu_colors[ENTRYCOLOR] =
  13412.                        CREATE_VIDEO_ATTRIBUTE(black,white);
  13413.            menu_colors[BORDERCOLOR] =
  13414.                        CREATE_VIDEO_ATTRIBUTE(black,white);
  13415.            menu_colors[HOTKEYCOLOR] =
  13416.                        CREATE_VIDEO_ATTRIBUTE(blue,white);
  13417.            menu_colors[HIGHLIGHTCOLOR] =
  13418.                        CREATE_VIDEO_ATTRIBUTE(black,cyan);
  13419.            menu_colors[UNAVAILCOLOR] =
  13420.                        CREATE_VIDEO_ATTRIBUTE(white,black);
  13421.              /* rest of the program */
  13422.          }
  13423.  
  13424.  
  13425.  
  13426.          Creating bar menu entries dynamically
  13427.          -------------------------------------
  13428.  
  13429.          You can create BAR_MENU_ENTRY's dynamically, instead of
  13430.          defining a pre-determined array of BAR_MENU_ENTRY's explained
  13431.          previously.  Here is an example:
  13432.  
  13433.  
  13434.          Usual method:
  13435.          ------------
  13436.  
  13437.          #include "menu.h"
  13438.          int menu_func();
  13439.  
  13440.          BAR_MENU_ENTRY bar_items[] = {
  13441.                  "File",1,4,'F',ALTF,menu_func,
  13442.                  "Edit",1,10,'E',0,menu_func,
  13443.                  "Run",1,17,'R',0,menu_func,
  13444.  
  13445.  
  13446.  
  13447.          Page 210          The C Window Library               Page 210
  13448.  
  13449.                  "Compile",1,23,'C',0,menu_func,
  13450.                  "Project",1,33,'P',0,menu_func,
  13451.                  "Options", 1,43,'O',0,menu_func,
  13452.                  "Debug",1,53,'D',0,menu_func,
  13453.                  "Break/watch",1,61,'B',0,menu_func,
  13454.                  CWL_NULL};
  13455.  
  13456.  
  13457.          Dymamic Method
  13458.          --------------
  13459.  
  13460.          #include "menu.h"
  13461.          #define NUMENTRIES 8
  13462.  
  13463.          BAR_MENU_ENTRY_PTR menu_array; /* Notice that we have a
  13464.                                            pointer to what
  13465.                                            will be an array of
  13466.                                            BAR_MENU_ENTRY's
  13467.                                          */
  13468.          BAR_MENU_PTR b;
  13469.  
  13470.          main()
  13471.          {
  13472.            WindowInitializeSystem();
  13473.  
  13474.            /* Initialize with at least number of total entries */
  13475.            menu_array = BarAllocate(NUMENTRIES);
  13476.  
  13477.            /* Call function to create entries
  13478.               in menu_array sequentially */
  13479.            BarCreateEntry(menu_array,/* BAR_MENU_ENTRY pointer */
  13480.                      1,              /* entry number */
  13481.  
  13482.            /* The rest of the arguments are just like the old method */
  13483.                      "File",         /* menu string */
  13484.                       1,             /* row number */
  13485.                       4,             /* col. number */
  13486.                      'F',            /* hotkey letter */
  13487.                      ALTF,           /* secondary hotkey */
  13488.                      menu_func);     /* function to perform */
  13489.  
  13490.            /* do rest of the entries */
  13491.            BarCreateEntry(menu_array,2,"Edit",1,10,'E',0,menu_func);
  13492.            BarCreateEntry(menu_array,3,"Run",1,17,'R',0,menu_func);
  13493.            BarCreateEntry(menu_array,4,"Compfile",1,23,'C',0,
  13494.                           menu_func);
  13495.            BarCreateEntry(menu_array,5,"Project",1,33,'P',0,menu_func);
  13496.            BarCreateEntry(menu_array,6,"Options",1,43,'O',0,menu_func);
  13497.            BarCreateEntry(menu_array,7,"Debug",  1,53,'D',0,menu_func);
  13498.            BarCreateEntry(menu_array,8,"Break/watch",1,61,'B',0,
  13499.                           menu_func);
  13500.  
  13501.            /* end all of the menu entries */
  13502.            BarEntryEnd(menu_array,NUMENTRIES);
  13503.  
  13504.  
  13505.  
  13506.  
  13507.          Page 211          The C Window Library               Page 211
  13508.  
  13509.            /* create menu */
  13510.            b = BarCreateMenu(menu_array, /* rest of the arguments */);
  13511.            /* ... */
  13512.  
  13513.            /* Dispose of menu entries created */
  13514.            BarDeallocate(menu_array);
  13515.          }
  13516.  
  13517.  
  13518.          The difference between the above method and the method used to
  13519.          globally initialize an array of BAR_MENU_ENTRY's are the
  13520.          following:
  13521.  
  13522.          1) The variable type for menu_array is BAR_MENU_ENTRY_PTR,
  13523.             not BAR_MENU_ENTRY as the normal method would have done.
  13524.  
  13525.          2) You must call the BarAllocate() function to allocate space
  13526.             for the number of entries desired.  If you do not call
  13527.             BarAllocate(), you will surely get a memory overwrite
  13528.             error.  The return value to BarAllocate() must be assigned
  13529.             to a BAR_MENU_ENTRY_PTR, as the above example shows.
  13530.  
  13531.             The array of menu entries are allocated from the heap at
  13532.             runtime, as opposed to the static method which sets up the
  13533.             memory scheme at link time.
  13534.  
  13535.          3) The next thing you must do is to fill in the entry
  13536.             information by calling the BarCreateEntry() function.  The
  13537.             first argument to the BarCreateEntry() function is the
  13538.             BAR_MENU_ENTRY_PTR.  The second argument is the entry
  13539.             number to assign this information to.  The rest of the
  13540.             arguments are the same order as the usual method i.e.
  13541.             menu string, row, column, hotkey, etc.  BarCreateEntry()
  13542.             is called for each field desired.
  13543.  
  13544.          4) The BarEndEntry() function must be called to terminate the
  13545.             list of entries.  The first argument is the
  13546.             BAR_MENU_ENTRY_PTR, and the second argument is the total
  13547.             number of entries defined.
  13548.  
  13549.          5) You should call BarDeallocate() to free the memory
  13550.             assigned to the array of menu_entries.  The only argument
  13551.             to BarDeallocate() is the BAR_MENU_ENTRY_PTR.  Only call
  13552.             BarDeallocate() after you have called BarMenuFree() or any
  13553.             function that disposes of the BAR_MENU_PTR.
  13554.  
  13555.  
  13556.          All of these functions except for BarAllocate() have no
  13557.          return values.  The BarAllocate() function returns a
  13558.          BAR_MENU_ENTRY_PTR if successful, and a null pointer if
  13559.          unsuccessful.
  13560.  
  13561.  
  13562.  
  13563.  
  13564.  
  13565.  
  13566.  
  13567.          Page 212          The C Window Library               Page 212
  13568.  
  13569.          You could also do the following:
  13570.  
  13571.          #include "menu.h"
  13572.          #define NUMENTRIES 8
  13573.  
  13574.          BAR_MENU_ENTRY menu_array[NUMENTRIES+1]; /* We must have at
  13575.                                                      least 1 more
  13576.                                          than the number of entries */
  13577.          BAR_MENU_PTR b;
  13578.  
  13579.          main()
  13580.          {
  13581.             /* ... */
  13582.  
  13583.            /* Call function to create entries
  13584.               in menu_array sequentially */
  13585.            BarCreateEntry(menu_array,   /* BAR_MENU_ENTRY pointer */
  13586.                      1,            /* entry number */
  13587.  
  13588.            /* The rest of the arguments are just like the old method */
  13589.                      "File", /* menu string */
  13590.                       1,     /* row number */
  13591.                       4,     /* col. number */
  13592.                      'F',    /* hotkey letter */
  13593.                      ALTF,   /* secondary hotkey */
  13594.                      menu_func);  /* function to perform */
  13595.  
  13596.  
  13597.            /* do rest of the entries */
  13598.            BarCreateEntry(menu_array,2,"Edit",1,10,'E',0,menu_func);
  13599.            BarCreateEntry(menu_array,3,"Run",1,17,'R',0,menu_func);
  13600.            BarCreateEntry(menu_array,4,"Compfile",1,23,'C',0,
  13601.                           menu_func);
  13602.            BarCreateEntry(menu_array,5,"Project",1,33,'P',0,menu_func);
  13603.            BarCreateEntry(menu_array,6,"Options",1,43,'O',0,menu_func);
  13604.            BarCreateEntry(menu_array,7,"Debug",  1,53,'D',0,menu_func);
  13605.            BarCreateEntry(menu_array,8,"Break/watch",1,61,'B',0,
  13606.                           menu_func);
  13607.  
  13608.            /* end all of the menu entries */
  13609.            BarEntryEnd(menu_array,NUMENTRIES);
  13610.          }
  13611.  
  13612.          The method above does not call BarAllocate() because the
  13613.          number of entries was already determined and an array was
  13614.          already set up at compile time.
  13615.  
  13616.          BarCreateEntry() is called for each menu entry as before, and
  13617.          BarEntryEnd() is called to terminate the menu entries.
  13618.  
  13619.          To use this method, you must declare an array of menu entries
  13620.          with at least one more than the desired number of entries.
  13621.          Also note that BarDeallocate() MUST NOT be called because the
  13622.          array of menu entries was not created with BarAllocate().
  13623.  
  13624.  
  13625.  
  13626.  
  13627.          Page 213          The C Window Library               Page 213
  13628.  
  13629.          BarCreateMenu() function
  13630.          ------------------------
  13631.  
  13632.          Now that you have created the BAR_MENU_ENTRY's, and defined
  13633.          the color scheme, it is time to wrap all of these loose ends
  13634.          in one package.  The next step is to call the BarCreateMenu()
  13635.          function.  This function combines all of the
  13636.          BAR_MENU_ENTRY's, the colors you have defined, and other
  13637.          information into one entity called a BAR_MENU_PTR.
  13638.  
  13639.          A BAR_MENU_PTR is a bar menu structure.  Just like a WPOINTER
  13640.          is a pointer to a window, a BAR_MENU_PTR is used to reference
  13641.          the bar menu.
  13642.  
  13643.          A prototype of the call to BarCreateMenu() is as follows:
  13644.  
  13645.  
  13646.  
  13647.          BAR_MENU_PTR BarCreateMenu(BAR_MENU_ENTRY *b, unsigned *c,
  13648.                                     int row, int col, unsigned options,
  13649.                                     WPOINTER (*wfunc)())
  13650.  
  13651.          To illustrate how to use this call, let's use the
  13652.          BAR_MENU_ENTRY's and colors created in the previous examples:
  13653.  
  13654.          #include "menu.h"
  13655.          int menu_func();
  13656.  
  13657.          BAR_MENU_ENTRY bar_items[] = {
  13658.                                       "File",1,4,'F',ALTF,NULLFN,
  13659.                                       "Edit",1,10,'E',0,edit,
  13660.                                       "Run",1,17,'R',0,NULLFN,
  13661.                                       "Compile",1,23,'C',0,NULLFN,
  13662.                                       "Project",1,33,'P',0,NULLFN,
  13663.                                       "Options", 1,43,'O',0,NULLFN,
  13664.                                       "Debug",1,53,'D',0,NULLFN,
  13665.                                       "Break/watch",1,61,'B',0,NULLFN,
  13666.                                       CWL_NULL};
  13667.  
  13668.          unsigned int menu_colors[5];
  13669.          BAR_MENU_PTR b;
  13670.  
  13671.          main()
  13672.          {
  13673.            WindowInitializeSystem(); /* Initialize C Window Library */
  13674.  
  13675.           /* define colors */
  13676.  
  13677.            menu_colors[ENTRYCOLOR] =
  13678.                            CREATE_VIDEO_ATTRIBUTE(black,white);
  13679.  
  13680.            menu_colors[BORDERCOLOR] =
  13681.                            CREATE_VIDEO_ATTRIBUTE(black,white);
  13682.  
  13683.  
  13684.  
  13685.  
  13686.  
  13687.          Page 214          The C Window Library               Page 214
  13688.  
  13689.            menu_colors[HOTKEYCOLOR] =
  13690.                            CREATE_VIDEO_ATTRIBUTE(blue,white);
  13691.  
  13692.            menu_colors[HIGHLIGHTCOLOR] =
  13693.                            CREATE_VIDEO_ATTRIBUTE(black,cyan);
  13694.  
  13695.            menu_colors[UNAVAILCOLOR] =
  13696.                            CREATE_VIDEO_ATTRIBUTE(white,black);
  13697.  
  13698.           /* create a BAR_MENU_PTR */
  13699.  
  13700.           WindowSaveInitial(0);  /* Save initial screen    */
  13701.           b = BarCreateMenu(menu_items,menu_colors,1,1,
  13702.                             NO_BAR_OPTIONS,WNULLFN);
  13703.          /* rest of the code */
  13704.          }
  13705.  
  13706.  
  13707.          In the example above there are two function calls that must
  13708.          be done before calling BarCreateMenu().  The first mandatory
  13709.          function is WindowInitializeSystem().  The other function
  13710.          must be WindowSaveInitial() The WindowInitializeSystem()
  13711.          function must be called to initialize global variables used
  13712.          by the menu manager.  The WindowSaveInitial() function is a
  13713.          mandatory function because the BarCreateMenu() function
  13714.          creates windows and assumes that the base screen has been
  13715.          saved.
  13716.  
  13717.  
  13718.          The example above declares the variable b to be a
  13719.          BAR_MENU_PTR.  This BAR_MENU_PTR is going to be used to
  13720.          reference the bar menu throughout the program.
  13721.  
  13722.          The first argument is a pointer to the first BAR_MENU_ENTRY.
  13723.          In the above example,  menu_items is a pointer to the first
  13724.          BAR_MENU_ENTRY.
  13725.  
  13726.          The second argument is a pointer to the array of colors.  In
  13727.          our example, menu_colors is our array of colors.
  13728.  
  13729.          The third and fourth arguments denote the row and column to
  13730.          place the upper left hand corner of the bar menu window.
  13731.  
  13732.          The fifth argument are various bar menu options that are
  13733.          assigned to the bar menus which are defined below.
  13734.  
  13735.  
  13736.  
  13737.          Bar Menu Options
  13738.          ----------------
  13739.  
  13740.          By default the menu manager assumes the following things:
  13741.  
  13742.            1)  The highlight bar does not wrap if the user wants to
  13743.                move the bar past the last entry, or before the first
  13744.                entry.
  13745.  
  13746.  
  13747.          Page 215          The C Window Library               Page 215
  13748.  
  13749.            2)  The menu will be hidden from the screen when a
  13750.                selection is made and will reappear when control is
  13751.                returned to the menu manager.
  13752.  
  13753.            3)  A function is automatically invoked when the hotkey is
  13754.                pressed instead of calling a user-defined function
  13755.                which will tell the menu manager whether the menu entry
  13756.                is to be executed.
  13757.  
  13758.            4)  The bar menu window is hidden when the menu manager
  13759.                returns control to the calling function.
  13760.  
  13761.            5)  The highlight bar will skip unavailable entries.
  13762.  
  13763.            6)  The menu manager does not recognize enhanced keys (F11,
  13764.                F12, etc.).
  13765.  
  13766.            7)  The mouse will not be used to move the highlight bar.
  13767.  
  13768.            8)  Scroll characters will not be displayed on the bar
  13769.                window.  The scroll characters allow the user to scroll
  13770.                through the options with a mouse.
  13771.  
  13772.  
  13773.          The last two options are only available if you have a
  13774.          Microsoft compatible mouse, and the mouse is activated.
  13775.  
  13776.          If the constant NO_BAR_OPTIONS is used, the assumptions above
  13777.          are used.  If you want to override the above defaults, use
  13778.          the following options:
  13779.  
  13780.             Option Name              Definition
  13781.             -----------              ----------
  13782.              BARWRAP             Highlight bar wrapping.
  13783.  
  13784.              BARSTATIC           Do not hide menu when selection is
  13785.                                  made.
  13786.  
  13787.              BARCONFIRM          Confirmation when selection is made
  13788.                                  via hotkey.
  13789.  
  13790.              BARDISPLAY          Display menu even after exit.
  13791.  
  13792.              BAROVERRIDE         Accept Unavailable entries.
  13793.  
  13794.              BARENHANCEDKEY      Recognize enhanced keys.
  13795.  
  13796.              BARMOUSE            Use the mouse to select entries.
  13797.  
  13798.          As was stated before, the last option, BARMOUSE  can only be
  13799.          used if you have a mouse installed, and the mouse is
  13800.          activated.  More information on these two options is given in
  13801.          the USING THE MOUSE section.
  13802.  
  13803.  
  13804.  
  13805.  
  13806.  
  13807.          Page 216          The C Window Library               Page 216
  13808.  
  13809.          By turning the above options "on" the following is assumed:
  13810.  
  13811.  
  13812.            1)  BARWRAP will wrap the highlight bar if the user wants
  13813.                to move the bar past the last entry or before the first
  13814.                entry.
  13815.  
  13816.            2)  BARSTATIC will not hide the menu when a selection is
  13817.                made.
  13818.  
  13819.            3)  BARCONFIRM will call a user-defined function before
  13820.                invoking the hotkey that was selected.  This function
  13821.                will then return an integer back to the menu manager
  13822.                informing whether the function selected should be
  13823.                invoked, or the request should be rejected.  There is
  13824.                more information on this option in the SETTING OPTIONS
  13825.                IN BAR MENUS section below.
  13826.  
  13827.            4)  BARDISPLAY will not hide the bar window when the menu
  13828.                manager returns control to the calling function.
  13829.  
  13830.            5)  BAROVERRIDE will make the menu manager accept
  13831.                unavailable entries.
  13832.  
  13833.            6)  BARENHANCEDKEY will inform the menu manager that
  13834.                enhanced keys will be recognized.
  13835.  
  13836.            7)  BARMOUSE allows the use of a mouse to make selections.
  13837.  
  13838.          You can also set multiple options by using a bitwise OR (|).
  13839.          For example:
  13840.  
  13841.            b = BarCreateMenu(arg1,arg2,arg3,arg4,
  13842.                              BARWRAP | BARSTATIC | BARCONFIRM,arg5)
  13843.  
  13844.          will set options BARWRAP, BARSTATIC, and BARCONFIRM defined
  13845.          above.
  13846.  
  13847.          The last argument to BarCreateMenu() is defined in the next
  13848.          sections.
  13849.  
  13850.  
  13851.  
  13852.          Default Bar Menu Window and Creating Your own Windows
  13853.          -----------------------------------------------------
  13854.  
  13855.          The sixth argument to the BarCreateMenu() function is a
  13856.          pointer to a function that will open a bar menu window.  If
  13857.          this is a NULL function pointer (WNULLFN), the menu manager
  13858.          will create a window.  For most applications, the window that
  13859.          the menu manager will create is adequate.  The menu manager
  13860.          uses these defaults when making the bar window:
  13861.  
  13862.           - A bordered window with the border consisting of single
  13863.             lines (SINGLEBOX).
  13864.  
  13865.  
  13866.  
  13867.          Page 217          The C Window Library               Page 217
  13868.  
  13869.           - The width of the window is determined by the longest row
  13870.             of entry names.
  13871.  
  13872.          If you want to create your own bar menu window, your function
  13873.          must return a WPOINTER.  Inside your function you must create
  13874.          and open a window using WindowInitialize() and WindowOpen().
  13875.          For most applications, you do not have to display the window,
  13876.          instead the menu manager can do the displaying and hiding of
  13877.          the windows.
  13878.  
  13879.  
  13880.          Here is an example of creating your own custom window
  13881.          function:
  13882.  
  13883.          #include "menu.h"
  13884.          /* Other includes and menu stuff */
  13885.          WPOINTER my_open();
  13886.  
  13887.          BAR_MENU_PTR b;
  13888.  
  13889.          main()
  13890.          {
  13891.             /*   Other code */
  13892.             b = BarCreateMenu(menu_items,menu_colors,1,1,
  13893.                               NO_BAR_OPTIONS,my_open);
  13894.             /* More code */
  13895.          }
  13896.  
  13897.  
  13898.  
  13899.          WPOINTER my_open()
  13900.          {
  13901.            WPOINTER w;
  13902.            w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,
  13903.                                 BLACKONWHITE,"");
  13904.            WindowOpen(w);
  13905.            return w;       /* May be null pointer,
  13906.                               but must return to BarCreateMenu() */
  13907.          }
  13908.  
  13909.  
  13910.          The example above lets the menu manager know that the window
  13911.          creation function is a user written function called my_open.
  13912.          The row, column and height arguments (arguments 3 and 4) of
  13913.          BarCreateMenu() will be ignored when using a custom window
  13914.          function.  The row and column height parameters used to
  13915.          create the window in the call to WindowInitialize() in
  13916.          my_window() will take precedence over the arguments 3 and 4
  13917.          used in BarCreateMenu().
  13918.  
  13919.          It is the programmer's responsibility to make sure that the
  13920.          window that is created is wide and tall enough to hold all of
  13921.          the menu entries.  If not, the results will be unpredictable.
  13922.  
  13923.  
  13924.  
  13925.  
  13926.  
  13927.          Page 218          The C Window Library               Page 218
  13928.  
  13929.          Accessing bar menu windows
  13930.          --------------------------
  13931.  
  13932.          After calling the BarCreateMenu() function, you can access
  13933.          the bar window by using the BAR_WINDOW() macro.  In the above
  13934.          example, b is the BAR_MENU_PTR and the value of BAR_WINDOW(b)
  13935.          is a pointer to the bar menu's window.  If you want to change
  13936.          borders move, slide, or anything you can do with normal
  13937.          windows, you must access the bar window in this way.
  13938.  
  13939.          For example, if you want to change the border of the bar
  13940.          window you would do the following:
  13941.  
  13942.              b = BarCreateMenu(...  /* other arguments */ )
  13943.  
  13944.              /* change border to a double lined box */
  13945.              WindowDrawBorder(BAR_WINDOW(b),DOUBLEBOX);
  13946.  
  13947.          The example calls WindowDrawBorder() to change the border of
  13948.          the bar window.
  13949.  
  13950.  
  13951.  
  13952.          Warnings
  13953.          --------
  13954.  
  13955.          Do not call WindowFree(), WindowClose() on the window of the
  13956.          bar menu.  The menu manager will call these functions when
  13957.          BarMenuFree() is called.  If you close the bar window on an
  13958.          active menu, the menu manager will assume that the bar window
  13959.          still exists.  Doing so will almost guarantee your
  13960.          application will bomb out.
  13961.  
  13962.  
  13963.  
  13964.          Return Values for BarCreateMenu()
  13965.          ---------------------------------
  13966.  
  13967.          If there are no errors, BarCreateMenu() returns a valid
  13968.          BAR_MENU_PTR pointer.  If there is an error when
  13969.          BarCreateMenu() is called, a null BAR_MENU_PTR is returned.
  13970.          Here are the possible reasons why an error has occurred:
  13971.  
  13972.            1) There is not enough memory to allocate for the
  13973.               BAR_MENU_PTR or its internal data structures.
  13974.  
  13975.            2) There is not enough memory to allocate for the bar
  13976.               window.
  13977.  
  13978.            3) The bar window's size was invalid.
  13979.  
  13980.          Problems 1 and 2 all are caused by a lack of heap memory.
  13981.          Problem 3 stems from having invalid parameters in the
  13982.          BarCreateMenu().  The arguments that are suspect are the
  13983.          third and fourth.  To remedy this problem, adjust these
  13984.          arguments such that the window can fit on the screen.
  13985.  
  13986.  
  13987.          Page 219          The C Window Library               Page 219
  13988.  
  13989.          For all of the above conditions, you can get the actual error
  13990.          code by checking the value of the global integer
  13991.          window_error_code.  If window_error_code is equal to
  13992.          NO_HEAP_MEM, then condition 1 or 2 has occurred.  If it is
  13993.          equal to BAD_WINDOW_SIZE, then condition 3 has occurred.
  13994.  
  13995.          If you have a custom window opening function, it is your
  13996.          responsibility to check the error conditions that may occur,
  13997.          and return a correct value or a null pointer if you cannot
  13998.          rectify the error in your custom routine.
  13999.  
  14000.  
  14001.          Here is an example:
  14002.  
  14003.               int status;
  14004.               BAR_MENU_PTR b;
  14005.               b = BarCreateMenu(...);
  14006.               if (b == (BAR_MENU_PTR)0)
  14007.               {
  14008.                 if (window_error_code == NO_HEAP_MEM)
  14009.                    /* ... Condition 1 or 2 occurred */
  14010.                 else
  14011.                   /* Condition 3 occurred */
  14012.               }
  14013.  
  14014.  
  14015.  
  14016.  
  14017.  
  14018.  
  14019.  
  14020.  
  14021.  
  14022.  
  14023.  
  14024.  
  14025.  
  14026.  
  14027.  
  14028.  
  14029.  
  14030.  
  14031.  
  14032.  
  14033.  
  14034.  
  14035.  
  14036.  
  14037.  
  14038.  
  14039.  
  14040.  
  14041.  
  14042.  
  14043.  
  14044.  
  14045.  
  14046.  
  14047.          Page 220          The C Window Library               Page 220
  14048.  
  14049.                       SELECTING FROM BAR MENUS
  14050.                       ------------------------
  14051.  
  14052.          We have now created the bar menu.  Now how do we get the menu
  14053.          manager to act on our bar window?  The answer is the
  14054.          BarSelectMenu() function.
  14055.  
  14056.  
  14057.          BarSelectMenu() function
  14058.          ------------------------
  14059.  
  14060.          The BarSelectMenu() function displays the bar window, and
  14061.          allows the user to move the highlight bar until he/she has
  14062.          placed the bar on the desired entry, or the user presses a
  14063.          hotkey to invoke one of the entries.
  14064.  
  14065.          Before the call to the BarSelectMenu(), nothing has been
  14066.          displayed.  This means that you can resize the bar window,
  14067.          change borders etc. while everything is hidden away from
  14068.          view.  The only time when the bar menu is displayed is when
  14069.          the call to BarSelectMenu() is made (or unless you have
  14070.          displayed the bar window yourself using WindowDisplay()).
  14071.  
  14072.          A prototype of the call to BarSelectMenu() is as follows:
  14073.  
  14074.          int BarSelectMenu(BAR_MENU_PTR b, int rank, unsigned start)
  14075.  
  14076.          The first argument is the BAR_MENU_PTR.  The second argument
  14077.          is the rank of the bar window.  As with other windows, the
  14078.          rank determines how the window will be situated on the screen
  14079.          with respect to the other windows.  The last argument is the
  14080.          number of the menu entry of where the highlight bar should be
  14081.          situated.  Usually this is 1, but this will give you the
  14082.          option to start on any one of the menu entries.  If the start
  14083.          value is out of bounds (say you have specified start to be 5
  14084.          while there are only 4 menu entries) the menu manager will
  14085.          default to the first menu entry.
  14086.  
  14087.          Now let's put everything together:
  14088.  
  14089.          #include "menu.h"
  14090.  
  14091.          int menu_func();
  14092.  
  14093.          BAR_MENU_ENTRY bar_items[] = {
  14094.                                "File",1,4,'F',ALTF,menu_func,
  14095.                                "Edit",1,10,'E',0,menu_func,
  14096.                                "Run",1,17,'R',0,menu_func,
  14097.                                "Compile",1,23,'C',0,menu_func,
  14098.                                "Project",1,33,'P',0,menu_func,
  14099.                                "Options", 1,43,'O',0,menu_func,
  14100.                                "Debug",1,53,'D',0,menu_func,
  14101.                                "Break/watch",1,61,'B',0,menu_func,
  14102.                                CWL_NULL};
  14103.  
  14104.  
  14105.  
  14106.  
  14107.          Page 221          The C Window Library               Page 221
  14108.  
  14109.          unsigned int menu_colors[5];
  14110.          BAR_MENU_PTR b;
  14111.  
  14112.          main()
  14113.          {
  14114.            WindowInitializeSystem();
  14115.            WindowSaveInitial(0);
  14116.            menu_colors[ENTRYCOLOR] =
  14117.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  14118.  
  14119.            menu_colors[BORDERCOLOR] =
  14120.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  14121.  
  14122.            menu_colors[HOTKEYCOLOR] =
  14123.                   CREATE_VIDEO_ATTRIBUTE(white,blue);
  14124.  
  14125.            menu_colors[HIGHLIGHTCOLOR] =
  14126.                   CREATE_VIDEO_ATTRIBUTE(cyan,black);
  14127.  
  14128.            menu_colors[UNAVAILCOLOR] =
  14129.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  14130.  
  14131.           /* create a BAR_MENU_PTR */
  14132.           b = BarCreateMenu(bar_items,menu_colors, 1,1,
  14133.                             BARSTATIC | BARWRAP,WNULLFN);
  14134.           BarSelectMenu(b,1,1);
  14135.          }
  14136.  
  14137.          int menu_func(BAR_MENU_PTR b, unsigned which)
  14138.          {
  14139.            WPOINTER w;
  14140.            w = WindowInitialize(BORDER,15,15,40,4,
  14141.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  14142.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  14143.                                 SINGLEBOX);
  14144.            WindowOpen(w);
  14145.            WindowPrintf(w,"You have selected %s",
  14146.                         BAR_ENTRY_STRING(b,which));
  14147.            WindowWriteCenterString(w,"Press a key to continue",3);
  14148.            WindowDisplay(w,1,NOEFFECT);
  14149.            GET_KEY();
  14150.            WindowFree(w,NOEFFECT);
  14151.            if (which == 9)
  14152.              return BAR_EXIT;
  14153.            else return BAR_CONTINUE;
  14154.          }
  14155.  
  14156.          The above example has a call to BarSelectMenu().  The
  14157.          arguments passed are b as the BAR_MENU_PTR, a window rank of
  14158.          1, and a starting position of 1.  The BAR_ENTRY_STRING()
  14159.          macro that is called in menu_func() returns the entry string
  14160.          of a desired entry in a BAR_MENU_PTR.  The first argument is
  14161.          the BAR_MENU_PTR, and the second argument is the entry number
  14162.          of the entry desired.
  14163.  
  14164.  
  14165.  
  14166.  
  14167.          Page 222          The C Window Library               Page 222
  14168.  
  14169.          Values passed to menu function
  14170.          ------------------------------
  14171.  
  14172.          When a selection is made, the menu manager will call the
  14173.          function defined for the selection, and pass two arguments to
  14174.          this function.  The first argument passed is the BAR_MENU_PTR
  14175.          of the current bar menu and the second argument is the number
  14176.          of the item selected.  Item numbers are numbered from 1 to
  14177.          the highest entry in the menu.  For example, if the "File"
  14178.          entry is selected, the menu manager will pass the
  14179.          BAR_MENU_PTR b, and a 1 to func().  If "Edit" is chosen, the
  14180.          menu manager passes a 2 as the second argument to func() etc.
  14181.  
  14182.  
  14183.          Values returned to menu manager
  14184.          -------------------------------
  14185.  
  14186.          The user function must return an integer back to the menu
  14187.          manager.  If the value returned to the menu manager is
  14188.          BAR_EXIT, the menu manager will exit from the current menu
  14189.          and will return control back to the function that called it.
  14190.          If the return value is BAR_CONTINUE, the menu continues to
  14191.          process selections.
  14192.  
  14193.          The menu_func() function defined above creates a window,
  14194.          displays the entry you have chosen, and returns a value back
  14195.          to the menu manager.  If the value is BAR_EXIT, the menu
  14196.          manager returns control back to the function that called it.
  14197.          In this case, main() called BarSelectMenu().  A return value
  14198.          of BAR_CONTINUE will cause the menu manager to let the user
  14199.          make another selection.
  14200.  
  14201.          The menu_func() function is a simple implementation.  However
  14202.          your function can do much more sophisticated things,
  14203.          including opening other bar menus.  If another bar menu is
  14204.          called while in another bar menu, the new bar menu gets its
  14205.          own menu manager and will not interfere with the original
  14206.          menu manager.  This is good if a menu function will call
  14207.          another menu function.
  14208.  
  14209.  
  14210.  
  14211.          Return Values for BarSelectMenu()
  14212.          ---------------------------------
  14213.  
  14214.          If no errors occurred when BarSelectMenu() is called the menu
  14215.          manager returns NO_ERROR when the menu is closed.  There are
  14216.          three possibilities for errors when calling BarSelectMenu().
  14217.          Here are the three possible errors:
  14218.  
  14219.          1) The bar menu's window does not exist.
  14220.  
  14221.          2) The bar menu's window is not opened.
  14222.  
  14223.          The first error occurred because the BarCreateMenu() function
  14224.  
  14225.  
  14226.  
  14227.          Page 223          The C Window Library               Page 223
  14228.  
  14229.          or your custom window function could not initialize the bar
  14230.          menu window, you inadvertently called WindowFree() on the bar
  14231.          menu's window, or you are overwriting data with a stray
  14232.          pointer.
  14233.  
  14234.          Error 2 can occur if the you inadvertently called
  14235.          WindowClose() on the bar menu's window, or you are
  14236.          overwriting data with a stray pointer.
  14237.  
  14238.          For all of the above conditions, you can get the actual error
  14239.          code by checking the value of the global integer
  14240.          window_error_code or by checking the return value of
  14241.          BarSelectMenu().  Here is a list of return values and their
  14242.          corresponding reasons:
  14243.  
  14244.  
  14245.            Return Value               Condition
  14246.            ------------               ---------
  14247.            BAD_WINDOW                    1
  14248.            WINDOW_NOT_OPEN               2
  14249.  
  14250.  
  14251.  
  14252.  
  14253.  
  14254.  
  14255.  
  14256.  
  14257.  
  14258.  
  14259.  
  14260.  
  14261.  
  14262.  
  14263.  
  14264.  
  14265.  
  14266.  
  14267.  
  14268.  
  14269.  
  14270.  
  14271.  
  14272.  
  14273.  
  14274.  
  14275.  
  14276.  
  14277.  
  14278.  
  14279.  
  14280.  
  14281.  
  14282.  
  14283.  
  14284.  
  14285.  
  14286.  
  14287.          Page 224          The C Window Library               Page 224
  14288.  
  14289.                     SETTING OPTIONS IN BAR MENUS
  14290.                     ----------------------------
  14291.  
  14292.          In addition to setting options using the BarCreateMenu()
  14293.          function, you can turn on and off options at any time using
  14294.          the BarSetOptions() function.
  14295.  
  14296.  
  14297.          The BarSetOptions() function
  14298.          ----------------------------
  14299.  
  14300.          The BarSetOptions() function turns either one or more of the
  14301.          above options on or off.  The prototype to the call is as
  14302.          follows:
  14303.  
  14304.          int BarSetOptions(BAR_MENU_PTR b, int option, int switch)
  14305.  
  14306.          The first argument is the BAR_MENU_PTR.  The second argument
  14307.          are the options that you wish to change.  The constants that
  14308.          describe the options are exactly the same as the ones
  14309.          described in BarCreateMenu().  The third argument is whether
  14310.          you want to switch the options on or off.
  14311.  
  14312.          Here are some sample calls to BarSetOptions():
  14313.  
  14314.              a) BarSetOptions(b,BARWRAP,1)
  14315.              b) BarSetOptions(b,BARSTATIC,1)
  14316.              c) BarSetOptions(b,BARCONFIRM,1)
  14317.              d) BarSetOptions(b,BARSTATIC,0)
  14318.              e) BarSetOptions(b,BARDISPLAY,1)
  14319.              f) BarSetOptions(b,BAROVERRIDE,1)
  14320.              g) BarSetOptions(b,BARENHANCEDKEY,1)
  14321.  
  14322.          The third argument is 1 for "on", 0 for "off".
  14323.  
  14324.          Example a) sets the highlight bar so that it will wrap.
  14325.  
  14326.          Example b) informs the menu manager that the menu will not be
  14327.          hidden when a selection is made.
  14328.  
  14329.          Example c) will tell the menu manager to call a user defined
  14330.          function that will inform the menu manager whether to invoke
  14331.          the selection in the menu.
  14332.  
  14333.          Example d) Informs the menu manager to hide the menu window
  14334.          when a menu function is invoked.
  14335.  
  14336.          Example e) Informs the menu manager not to hide the menu when
  14337.          control is returned to the function that called
  14338.          BarSelectMenu().
  14339.  
  14340.          Example f) Informs the menu manager to process unavailable
  14341.          entries.  This is useful if you want to set up your own error
  14342.          routine if the user selects an unavailable entry.
  14343.  
  14344.  
  14345.  
  14346.  
  14347.          Page 225          The C Window Library               Page 225
  14348.  
  14349.          Example g) imforms the menu manager to distinguish between
  14350.          normal keys and enhanced keys.
  14351.  
  14352.  
  14353.  
  14354.          Setting Multiple Options
  14355.          ------------------------
  14356.  
  14357.          You can also set multiple options with a single call by using
  14358.          a bitwise OR (|).  For example:
  14359.  
  14360.          BarSetOptions(b,BARWRAP | BARSTATIC | BARCONFIRM,1)
  14361.  
  14362.          will set options BARWRAP, BARSTATIC, and BARCONFIRM defined
  14363.          above.
  14364.  
  14365.  
  14366.  
  14367.          Setting the BarSetConfirmFunction()
  14368.          -----------------------------------
  14369.  
  14370.          When using the BARCONFIRM option, you must also use the
  14371.          BarSetConfirmFunction() function to point the menu to the
  14372.          confirmation function that will be called when a hotkey is
  14373.          pressed.  Here is a prototype of the BarSetConfirmFunction():
  14374.  
  14375.          int BarSetConfirmFunction(BAR_MENU_PTR b, int (*func)())
  14376.  
  14377.          where b is the desired bar menu to assign the confirmation
  14378.          function to, and func is a pointer to a function that will
  14379.          return a value back to the menu manager that will inform it
  14380.          to either invoke the option, or ignore the option.
  14381.  
  14382.          When the confirmation function is called, the menu manager
  14383.          passes three arguments to func.  The prototype for your user
  14384.          defined function should be as follows:
  14385.  
  14386.          int my_confirm_func(BAR_MENU_PTR b, unsigned key,
  14387.                              unsigned sel)
  14388.  
  14389.          where b is the BAR_MENU_PTR that is currently being
  14390.          processed, key is the hotkey that was pressed, and sel is the
  14391.          selection where the highlight bar is now positioned.  The
  14392.          highlight bar is always positioned on the hotkey selection
  14393.          even if it may not be invoked.  This user defined function
  14394.          must return a value back to the menu manager.  The valid
  14395.          values that can be returned are BAR_CONTINUE and
  14396.          BAR_DO_CHOICE.  If BAR_CONTINUE is returned, the menu
  14397.          selection is not invoked, if BAR_DO_CHOICE is selected, the
  14398.          menu entry is invoked.  Here is an example:
  14399.  
  14400.             #include "menu.h"
  14401.  
  14402.             int my_confirm_func();
  14403.             BAR_MENU_PTR b;
  14404.  
  14405.  
  14406.  
  14407.          Page 226          The C Window Library               Page 226
  14408.  
  14409.             /* ... */
  14410.             main()
  14411.             {
  14412.               BarSetOptions(b,BARCONFIRM,1);
  14413.               BarSetConfirmFunction(b,my_confirm_func);
  14414.               /* ... */
  14415.             }
  14416.  
  14417.             my_confirm_func(BAR_MENU_PTR b, unsigned k, unsigned sel)
  14418.             {
  14419.               /* ... */
  14420.               if (k == 'C' || k == 'c' || k == ALTF)
  14421.                 return BAR_CONTINUE;
  14422.               else
  14423.                 return BAR_DO_CHOICE;
  14424.             }
  14425.  
  14426.          The above function invokes the menu selection if the hotkey
  14427.          that was pressed is not a 'C', 'c', or ALT-F.
  14428.  
  14429.          The confirmation function can do anything, including setting
  14430.          options in the bar menu, displaying other windows etc.
  14431.  
  14432.  
  14433.  
  14434.          Return Values for BarSetOptions() function
  14435.          ------------------------------------------
  14436.  
  14437.          You can use the BarSetOptions() function at any time,
  14438.          including before calling the BarSelectMenu() function.  If
  14439.          the option is not a valid option, the function returns
  14440.          NO_ERROR, but does not change anything.  If the switch is not
  14441.          0 or 1, a 1 is assumed.
  14442.  
  14443.          If there is an error, the error conditions and reasons are
  14444.          the same as the BarSelectMenu() function defined above.
  14445.  
  14446.  
  14447.  
  14448.  
  14449.  
  14450.  
  14451.  
  14452.  
  14453.  
  14454.  
  14455.  
  14456.  
  14457.  
  14458.  
  14459.  
  14460.  
  14461.  
  14462.  
  14463.  
  14464.  
  14465.  
  14466.  
  14467.          Page 227          The C Window Library               Page 227
  14468.  
  14469.               MAKING ENTRIES AVAILABLE AND UNAVAILABLE
  14470.               ----------------------------------------
  14471.  
  14472.          There may be cases when a menu entry should be made
  14473.          unavailable.  The entry shows up in the menu, but it is a
  14474.          different color than the other entries, and the highlight bar
  14475.          will just skip over this unavailable entry.
  14476.  
  14477.  
  14478.          BarMakeEntryAvailable() and
  14479.          BarMakeEntryUnavailable() functions
  14480.          -----------------------------------
  14481.  
  14482.          With The C Window Library, you can make entries available and
  14483.          unavailable at any time.  The BarMakeEntryAvailable() and the
  14484.          BarMakeEntryUnavailable() functions perform these tasks.
  14485.  
  14486.          A prototype of the call to both of these functions is as
  14487.          follows:
  14488.  
  14489.          int BarMakeEntryAvailable(BAR_MENU_PTR b, unsigned entry)
  14490.          int BarMakeEntryUnavailable(BAR_MENU_PTR b, unsigned entry)
  14491.  
  14492.          The first argument is the BAR_MENU_PTR.  The second argument
  14493.          is the number of the entry that you wish to change.  Entry
  14494.          numbers range from 1 to the highest entry in the menu.
  14495.  
  14496.  
  14497.  
  14498.          BAROVERRIDE option
  14499.          ------------------
  14500.  
  14501.          If the BAROVERRIDE option is set (see above), the menu
  14502.          manager will still process unavailable entries.  You must
  14503.          turn off BAROVERRIDE by using the BarSetOptions() function if
  14504.          you do not want to process unavailable entries.
  14505.  
  14506.  
  14507.          Return Values for BarMakeEntryAvaialble() and
  14508.          BarMakeEntryUnavailable() functions
  14509.          ---------------------------------------------
  14510.  
  14511.          If there is no error, both of these functions return
  14512.          NO_ERROR.  If there is an error, the following possibilities
  14513.          can occur:
  14514.  
  14515.          1) The error can be one of the errors defined above for the
  14516.             BarSelectMenu().
  14517.  
  14518.          2) The menu entry is invalid.
  14519.  
  14520.          Refer to the BarSelectMenu() return values and reasons for
  14521.          failure defined above for error condition 1).  If the error
  14522.          is 2), check to see if the entry number supplied is valid.
  14523.          The entry number cannot be < 1 or greater than the number of
  14524.  
  14525.  
  14526.  
  14527.          Page 228          The C Window Library               Page 228
  14528.  
  14529.          selections in the bar menu.
  14530.  
  14531.          If error 2) has occurred, the BarMakeEntryAvailable() and the
  14532.          BarMakeEntryUnavailable() return MENU_ENTRY_INVALID.
  14533.  
  14534.  
  14535.  
  14536.  
  14537.  
  14538.  
  14539.  
  14540.  
  14541.  
  14542.  
  14543.  
  14544.  
  14545.  
  14546.  
  14547.  
  14548.  
  14549.  
  14550.  
  14551.  
  14552.  
  14553.  
  14554.  
  14555.  
  14556.  
  14557.  
  14558.  
  14559.  
  14560.  
  14561.  
  14562.  
  14563.  
  14564.  
  14565.  
  14566.  
  14567.  
  14568.  
  14569.  
  14570.  
  14571.  
  14572.  
  14573.  
  14574.  
  14575.  
  14576.  
  14577.  
  14578.  
  14579.  
  14580.  
  14581.  
  14582.  
  14583.  
  14584.  
  14585.  
  14586.  
  14587.          Page 229          The C Window Library               Page 229
  14588.  
  14589.                   CHANGING THE MENU OPTIONS STRING
  14590.                   --------------------------------
  14591.  
  14592.          There may be times when you want to change a BAR_MENU_ENTRY
  14593.          entry_name string.  For instance, you may have a menu entry
  14594.          with the following entry_name:
  14595.  
  14596.                  "Default File Name     ABC.DAT"
  14597.  
  14598.  
  14599.          If the user selects this choice, the file name should change
  14600.          to another file name the user wants.  From there the menu
  14601.          should reflect the new choice the user has made.  Let's say
  14602.          the user has changed the default file name to DEF.DAT.  The
  14603.          menu then should say:
  14604.  
  14605.  
  14606.                  "Default File Name     DEF.DAT"
  14607.  
  14608.  
  14609.  
  14610.  
  14611.          BarChangeEntryString() function
  14612.          -------------------------------
  14613.  
  14614.          How do you change the entry string?  One way is to fool
  14615.          around with the BAR_MENU_PTR's structure members, and change
  14616.          the string yourself.  This is not recommended for the novice
  14617.          to average C programmer, since it is not a good idea to
  14618.          change the structure members directly without a full
  14619.          understanding of the structure.
  14620.  
  14621.          A safer way is to call the BarChangeEntryString() function.
  14622.          A prototype of this function is as follows:
  14623.  
  14624.          int BarChangeEntryString(BAR_MENU_PTR b, unsigned entry,
  14625.                                   char *newstring)
  14626.  
  14627.          The first argument is the BAR_MENU_PTR.  The second argument
  14628.          is the number of the entry that you wish to change.  Entry
  14629.          numbers range from 1 to the highest entry in the menu.  The
  14630.          third argument is a pointer to the new character string.
  14631.          Remember that the width of the bar menu's window is equal to
  14632.          the width of the longest line of entry_name entries,
  14633.          therefore newstring cannot exceed the boundaries of the bar
  14634.          menu window (unless you will called WindowResizeWidth() or
  14635.          WindowResizeHeight() to resize the window).
  14636.  
  14637.  
  14638.  
  14639.          Return Values for BarChangeEntryString() function
  14640.          -------------------------------------------------
  14641.  
  14642.          If there is no error, then NO_ERROR is returned.
  14643.  
  14644.  
  14645.  
  14646.  
  14647.          Page 230          The C Window Library               Page 230
  14648.  
  14649.          If there is an error, the error conditions and reasons are
  14650.          the same as the BarMakeEntryAvailable() function defined
  14651.          above.
  14652.  
  14653.  
  14654.  
  14655.  
  14656.  
  14657.  
  14658.  
  14659.  
  14660.  
  14661.  
  14662.  
  14663.  
  14664.  
  14665.  
  14666.  
  14667.  
  14668.  
  14669.  
  14670.  
  14671.  
  14672.  
  14673.  
  14674.  
  14675.  
  14676.  
  14677.  
  14678.  
  14679.  
  14680.  
  14681.  
  14682.  
  14683.  
  14684.  
  14685.  
  14686.  
  14687.  
  14688.  
  14689.  
  14690.  
  14691.  
  14692.  
  14693.  
  14694.  
  14695.  
  14696.  
  14697.  
  14698.  
  14699.  
  14700.  
  14701.  
  14702.  
  14703.  
  14704.  
  14705.  
  14706.  
  14707.          Page 231          The C Window Library               Page 231
  14708.  
  14709.                       REDEFINING THE MENU KEYS
  14710.                       ------------------------
  14711.  
  14712.  
  14713.          Setting Global Key Definitions and
  14714.          the bar_key_definition Array
  14715.          ----------------------------------
  14716.  
  14717.          You can redefine the keys used to control moving the
  14718.          highlight bar, accepting the menu choice, and exiting from
  14719.          the menu.  Here is a list of the default key mapping:
  14720.  
  14721.            Function                    Key             Constant
  14722.            --------                    ---              ------
  14723.          Move highlight bar right    Up Arrow        BAR_RIGHTKEY
  14724.          Move highlight bar left     Down Arrow      BAR_LEFTKEY
  14725.          Accept Menu Choice          Enter           BAR_ACCEPTKEY
  14726.          Escape Bar menu             Escape          BAR_QUITKEY
  14727.          Move To First Menu Item     Home            BAR_HOMEKEY
  14728.          Move to Last Menu Item      End             BAR_ENDKEY
  14729.  
  14730.          The global array bar_key_definition contains the values of
  14731.          the default bar menu key definitions.  The names under the
  14732.          Constant heading are the offsets in the bar_key_definition
  14733.          array of where the key value for the function is defined.
  14734.          For instance, the value for the "Move highlight bar up"
  14735.          function is located at bar_key_definition[BAR_RIGHTKEY].  You
  14736.          can change the values in bar_key_definition at any time, but
  14737.          make sure that a definition for "Escape Bar menu" always
  14738.          exists, and that there are no duplicate definitions (i.e.
  14739.          the "Move highlight bar up" key definition is the same as the
  14740.          "Move highlight bar down" key definition).  When defining new
  14741.          key values, you should use the values defined in the
  14742.          keycodes.h header file for non-ascii keys.
  14743.  
  14744.  
  14745.  
  14746.          Setting Local Key Definitions
  14747.          -----------------------------
  14748.  
  14749.          Another way of redefining menu keys is to load your own array
  14750.          of key definitions with your desired values, and then calling
  14751.          the BarAssignKeys() function.  With this method, each menu
  14752.          can have different key definitions.
  14753.  
  14754.  
  14755.  
  14756.          BarAssignKeys() function
  14757.          ------------------------
  14758.  
  14759.          Here is a prototype of the BarAssignKeys() function:
  14760.  
  14761.             int BarAssignKeys(BAR_MENU_PTR b, unsigned *keys)
  14762.  
  14763.          where b is the BAR_MENU_PTR, and keys is an array of key
  14764.  
  14765.  
  14766.  
  14767.          Page 232          The C Window Library               Page 232
  14768.  
  14769.          definitions.  Here is a small code example:
  14770.  
  14771.          #include "menu.h"
  14772.  
  14773.          unsigned mykeys[8] = {CTRLR,CTRLL,RETURN,ESC,HOME,END};
  14774.          BAR_MENU_PTR b;
  14775.  
  14776.          /* Other stuff...*/
  14777.  
  14778.          main()
  14779.          {
  14780.            /* Assume b is initialized */
  14781.  
  14782.            BarAssignKeys(b,mykeys); /* Assigns my key
  14783.                                        definitions to bar menu b */
  14784.          }
  14785.  
  14786.          The above example uses the constants defined in keycodes.h to
  14787.          assign to the array mykeys.  Each position in the mykeys
  14788.          array uses the default key mapping explained above.  In other
  14789.          words, mykeys[BAR_RIGHTKEY] is CTRLR, etc.
  14790.  
  14791.  
  14792.  
  14793.          Return Values for BarAssignKeys() function
  14794.          ------------------------------------------
  14795.  
  14796.          If there is no error, then NO_ERROR is returned.
  14797.  
  14798.          If there is an error, the error conditions and reasons are
  14799.          the same as the BarSelectMenu() function defined above.
  14800.  
  14801.  
  14802.  
  14803.  
  14804.  
  14805.  
  14806.  
  14807.  
  14808.  
  14809.  
  14810.  
  14811.  
  14812.  
  14813.  
  14814.  
  14815.  
  14816.  
  14817.  
  14818.  
  14819.  
  14820.  
  14821.  
  14822.  
  14823.  
  14824.  
  14825.  
  14826.  
  14827.          Page 233          The C Window Library               Page 233
  14828.  
  14829.                       PROCESSING UNDEFINED KEYS
  14830.                       -------------------------
  14831.  
  14832.          If you are an advanced programmer and/or have experience in
  14833.          using other window/menu libraries, you may be wondering "how
  14834.          do I define a function that supplies context-sensitive help
  14835.          for each BAR_MENU_ENTRY?  There is no structure member in
  14836.          BAR_MENU_ENTRY that supplies this".  With The C Window
  14837.          Library, any key that is not recognized by the menu manager
  14838.          (i.e. the key struck does not invoke a menu option, move the
  14839.          highlight bar up or down, or ends processing of the menu) can
  14840.          be processed by calling a user written function.   The
  14841.          WindowGet...() family of functions allowed us to define a
  14842.          function that will be called if a key that has no current
  14843.          definition is pressed.  For bar menus, we can do the same
  14844.          thing.
  14845.  
  14846.  
  14847.          The bar_undef_key function pointer
  14848.          ----------------------------------
  14849.  
  14850.          The global function pointer, bar_undef_key, can point to a
  14851.          user written function that will be called when the menu
  14852.          manager encounters a key that is not defined.  The
  14853.          declaration for bar_undef_key is as follows:
  14854.  
  14855.          unsigned int (*bar_undef_key)(BAR_MENU_PTR b, unsigned sel,
  14856.                                        unsigned int *choice)
  14857.  
  14858.          The user written function takes three arguments.  The first
  14859.          argument is a pointer to the bar menu that the menu manager
  14860.          is currently processing. The second argument is an integer
  14861.          that contains the value of the key that was pressed.  The
  14862.          third argument is a pointer to an integer that will contain
  14863.          the number of the menu choice to execute.  Initially, choice
  14864.          points to an integer that contains the current menu choice
  14865.          that the menu highlight bar is situated.  For instance, if
  14866.          the highlight bar is on the first menu choice when an
  14867.          undefined key is pressed, *choice will be equal to 1.  If
  14868.          bar_undef_key is equal to a Null Function pointer (NULLFN),
  14869.          no user defined function is called.  By default,
  14870.          bar_undef_key is assigned to NULLFN.
  14871.  
  14872.  
  14873.          Values returned to menu manager
  14874.          -------------------------------
  14875.  
  14876.          If bar_undef_key is assigned to a function, the function must
  14877.          return an integer back to the menu manager.  This integer
  14878.          value will tell the menu manager how to proceed.  Here is a
  14879.          list of the valid return values that the user written
  14880.          function can return:
  14881.  
  14882.  
  14883.  
  14884.  
  14885.  
  14886.  
  14887.          Page 234          The C Window Library               Page 234
  14888.  
  14889.            Return                         Action to
  14890.            Value                            Take
  14891.            ------                         ---------
  14892.           BAR_CONTINUE          No Action. Continue processing the bar
  14893.                                 menu.
  14894.  
  14895.           BAR_DO_CHOICE         Accept and invoke menu entry assigned
  14896.                                 to *choice.
  14897.  
  14898.           BAR_MOVE_CONTINUE     Move the highlight bar to menu entry
  14899.                                 assigned to *choice and continue
  14900.                                 processing menu.
  14901.  
  14902.           BAR_ESCAPE            Escape the bar menu.
  14903.  
  14904.           BAR_MOVE_LEFT         Move to next bar menu.
  14905.  
  14906.           BAR_MOVE_RIGHT        Move to previous bar menu.
  14907.  
  14908.           BAR_MOVE_HOME         Move highlight to first available menu
  14909.                                 entry.
  14910.  
  14911.           BAR_MOVE_END          Move highlight to last available menu
  14912.                                 entry.
  14913.  
  14914.          A return value of BAR_CONTINUE is a "do nothing" command to
  14915.          the menu manager.
  14916.  
  14917.          If BAR_DO_CHOICE is returned to the menu manager, the integer
  14918.          assigned to the parameter *choice is used as the menu entry
  14919.          to invoke.  The highlight bar will automatically be moved to
  14920.          the menu choice specified, and the menu function will be
  14921.          called.  If BAR_MOVE_CONTINUE is returned to the menu
  14922.          manager, the highlight bar will be moved to the entry
  14923.          specified by the value of *choice, but no function is called.
  14924.  
  14925.          Return values of BAR_DO_CHOICE and BAR_MOVE_CONTINUE only
  14926.          work when the menu entry specified by *choice is an available
  14927.          entry or the BAROVERRIDE option is on , otherwise the menu
  14928.          manager just continues processing the bar menu.
  14929.  
  14930.  
  14931.          Here is an example of using a user defined function for the
  14932.          undefined keys:
  14933.  
  14934.  
  14935.          #include "menu.h"
  14936.  
  14937.          /*  Other includes */
  14938.  
  14939.          int user_func();
  14940.  
  14941.  
  14942.  
  14943.  
  14944.  
  14945.  
  14946.  
  14947.          Page 235          The C Window Library               Page 235
  14948.  
  14949.          main()
  14950.          {
  14951.            bar_undef_key = user_func;
  14952.  
  14953.            /* Other code */
  14954.          }
  14955.  
  14956.  
  14957.          unsigned int user_func(BAR_MENU_PTR b, unsigned sel,
  14958.                                 unsigned *choice)
  14959.          {
  14960.            switch(sel)
  14961.  
  14962.            {
  14963.              case F1:
  14964.                help(*choice);         /* call help function */
  14965.                return BAR_CONTINUE; /* return "do nothing" command */
  14966.  
  14967.              case F2:
  14968.                *choice = 6;  /* do choice 6 on the menu */
  14969.                return BAR_DO_CHOICE;
  14970.  
  14971.              default:
  14972.                return BAR_CONTINUE;
  14973.                /* let menu manager know not to do anything */
  14974.            }
  14975.          }
  14976.  
  14977.          int help(int choice)
  14978.          {  /* help function */
  14979.            switch (choice)
  14980.            {
  14981.              case 1:
  14982.                /* do context-sensitive help for entry 1 */
  14983.              break;
  14984.              case 2:
  14985.                /* do context-sensitive help for entry 2 */
  14986.              break;
  14987.               /* do more entries */
  14988.               /* ... */
  14989.            }
  14990.          }
  14991.  
  14992.          In the above example, if the user hits F1, a help function is
  14993.          called.  If you wanted to know how to incorporate a help
  14994.          function in the bar menus, here is the way to do it.
  14995.  
  14996.          If the user hits F2, the integer pointed to by choice is
  14997.          assigned a 6, and user_func() returns BAR_DO_CHOICE to the
  14998.          menu manager.  This tells the menu manager to invoke the
  14999.          function assigned to menu entry 6.
  15000.  
  15001.  
  15002.  
  15003.  
  15004.  
  15005.  
  15006.  
  15007.          Page 236          The C Window Library               Page 236
  15008.  
  15009.                          PRE-INPUT FUNCTION
  15010.                          ------------------
  15011.  
  15012.          With The C Window Library, you can define a function that
  15013.          will be performed just before the menu manager waits for the
  15014.          user to enter a keystroke.  This function can perform just
  15015.          about anything.
  15016.  
  15017.  
  15018.          Setting the global_bar_prefunc function pointer
  15019.          -------------------------------------------------
  15020.  
  15021.          The global_bar_prefunc function pointer points to this user
  15022.          written function.  Here is the prototype:
  15023.  
  15024.          int (*global_bar_prefunc)(BAR_MENU_PTR p, unsigned *sel)
  15025.  
  15026.          The arguments that will be passed to your function are the
  15027.          following:
  15028.  
  15029.          a)  The BAR_MENU_PTR of the bar menu that called your
  15030.              function, and
  15031.  
  15032.          b)  A pointer to the number of the selection that the
  15033.              highlight bar is currently on.
  15034.  
  15035.          The selection number ranges from 1 to the highest entry
  15036.          number of the menu.
  15037.  
  15038.          The pre-input function MUST return a value back to the menu
  15039.          manager.  The return values that can be returned are the same
  15040.          as the bar_undef_key function described above.  If you are
  15041.          using a version of The C Window Library prior to version 1.5,
  15042.          you must declare your pre-input function as returning an int,
  15043.          and you must return a value back to the menu manager.
  15044.          Versions prior to 1.5 declared the pre-input function as
  15045.          void.
  15046.  
  15047.          The BAR_DO_CHOICE and BAR_MOVE_CONTINUE return values will
  15048.          move the highlight bar to the entry number that is assigned
  15049.          to the *sel argument when the pre-input function has
  15050.          returned.
  15051.  
  15052.          By default, global_bar_prefunc points to a NULLFN, and
  15053.          therefore will not be performed.  However, you can implement
  15054.          pre-input functions depending on the current selection.  For
  15055.          instance, you can write a function that displays extra
  15056.          information for each entry like so:
  15057.  
  15058.          #include "menu.h"
  15059.  
  15060.          char *mess[] = {
  15061.                    " This option saves and loads files",
  15062.                    " This brings you in edit mode",
  15063.                    " This compiles and/or links the current program",
  15064.  
  15065.  
  15066.  
  15067.          Page 237          The C Window Library               Page 237
  15068.  
  15069.                           /* ... More stuff */
  15070.                    };
  15071.  
  15072.  
  15073.          WPOINTER message_window;
  15074.  
  15075.          int disp_info();
  15076.  
  15077.          main()
  15078.          {
  15079.            /* ... */
  15080.  
  15081.            global_bar_prefunc = disp_info;
  15082.  
  15083.            /* ... */
  15084.          }
  15085.  
  15086.          int disp_info(BAR_MENU_PTR p, unsigned *sel)
  15087.          {
  15088.             /* Assume message_window already created and opened */
  15089.  
  15090.            WindowClear(message_window,
  15091.                        CREATE_VIDEO_ATTRIBUTE(black,white));
  15092.            WindowWriteString(message_window,mess[*sel-1],1,1);
  15093.            return BAR_CONTINUE;
  15094.          }
  15095.  
  15096.  
  15097.          For simplicity, the menu definitions are left out of the
  15098.          preceding code sample.  The disp_info displays the
  15099.          appropriate description in the window message_window.
  15100.          BAR_CONTINUE is returned to the menu manager.  This informs
  15101.          the menu manager to continue looking for a keystroke.
  15102.  
  15103.  
  15104.  
  15105.  
  15106.  
  15107.  
  15108.  
  15109.  
  15110.  
  15111.  
  15112.  
  15113.  
  15114.  
  15115.  
  15116.  
  15117.  
  15118.  
  15119.  
  15120.  
  15121.  
  15122.  
  15123.  
  15124.  
  15125.  
  15126.  
  15127.          Page 238          The C Window Library               Page 238
  15128.  
  15129.                        DISPOSING OF BAR MENUS
  15130.                        ----------------------
  15131.  
  15132.          BarMenuFree() function
  15133.          ----------------------
  15134.  
  15135.          If the bar menu is no longer needed, the BarMenuFree()
  15136.          function will dispose of the bar menu and return any memory
  15137.          allocated to the bar menu, window, and  window memory back to
  15138.          the heap.  The call to the function is very simple:
  15139.  
  15140.                 BarMenuFree(BAR_MENU_PTR b)
  15141.  
  15142.          where b is the BAR_MENU_PTR to dispose of.  Since this
  15143.          function destroys the BAR_MENU_PTR b, b must not be used for
  15144.          any bar menu functions, unless b is pointing to a valid
  15145.          BAR_MENU_PTR.
  15146.  
  15147.  
  15148.  
  15149.          Return Values for BarMenuFree()
  15150.          -------------------------------
  15151.  
  15152.          The return values and the reasons for failure are the same as
  15153.          BarSelectMenu().  Please refer to this section.
  15154.  
  15155.  
  15156.  
  15157.  
  15158.  
  15159.  
  15160.  
  15161.  
  15162.  
  15163.  
  15164.  
  15165.  
  15166.  
  15167.  
  15168.  
  15169.  
  15170.  
  15171.  
  15172.  
  15173.  
  15174.  
  15175.  
  15176.  
  15177.  
  15178.  
  15179.  
  15180.  
  15181.  
  15182.  
  15183.  
  15184.  
  15185.  
  15186.  
  15187.          Page 239          The C Window Library               Page 239
  15188.  
  15189.                            PULLDOWN MENUS
  15190.                            --------------
  15191.  
  15192.          Description
  15193.          -----------
  15194.  
  15195.          A pulldown menu is a combination of popup menus and a bar
  15196.          menu.  The bar menu portion of the pulldown menu acts the
  15197.          same way as a normal bar menu.  However when a choice is made
  15198.          from the bar menu, a popup menu appears with more options to
  15199.          choose.  An example of a pulldown menu is the integrated
  15200.          environ- ments of the Quick C and Turbo C compilers.
  15201.  
  15202.          Most of what was discussed previously will apply to pulldown
  15203.          menus.  Make sure that you have read the sections on popup
  15204.          menus and bar menus before preceding.
  15205.  
  15206.  
  15207.  
  15208.          Bar Menu and Popup Menu levels
  15209.          ------------------------------
  15210.  
  15211.          With pulldown menus there are two levels; the bar menu level
  15212.          and the popup menu level.  When in the bar menu level, no
  15213.          popup menu's are displayed, and the move right and move left
  15214.          keys move the highlight bar to the next or previous selection
  15215.          in the bar menu.  When in the popup menu level, the move
  15216.          right and move left keys not only move the highlight in the
  15217.          bar menu, but will also display the popup menu associated
  15218.          with the bar menu option.
  15219.  
  15220.  
  15221.  
  15222.  
  15223.  
  15224.  
  15225.  
  15226.  
  15227.  
  15228.  
  15229.  
  15230.  
  15231.  
  15232.  
  15233.  
  15234.  
  15235.  
  15236.  
  15237.  
  15238.  
  15239.  
  15240.  
  15241.  
  15242.  
  15243.  
  15244.  
  15245.  
  15246.  
  15247.          Page 240          The C Window Library               Page 240
  15248.  
  15249.                        CREATING PULLDOWN MENUS
  15250.                        -----------------------
  15251.  
  15252.  
  15253.          There are 4 steps that must be done when creating pulldown
  15254.          menus.  They are as follows:
  15255.  
  15256.             Step 1)  Create the bar menu portion by calling
  15257.                      BarCreateMenu().
  15258.  
  15259.             Step 2)  Create each popup menu to be displayed underneath
  15260.                      the bar by calling the PopupCreateMenu()
  15261.                      function.
  15262.  
  15263.             Step 3)  Group all popup menus created in step 2 into an
  15264.                      array of popup menu's.
  15265.  
  15266.             Step 4)  Call PulldownCreateMenu().
  15267.  
  15268.  
  15269.  
  15270.          For Step 1) the bar menu is created the same way as described
  15271.          in the Bar Menu section of this manual.  The only difference
  15272.          is that if there is a popup window that will be displayed
  15273.          under the bar menu option, the function pointer for that
  15274.          BAR_MENU_ENTRY must be a NULLFN (null integer function
  15275.          pointer).  Otherwise, if there is no popup menu defined for
  15276.          that bar menu option, the BAR_MENU_ENTRY's function pointer
  15277.          must point to a valid function.  For instance, here is a
  15278.          sample array of BAR_MENU_ENTRY's used to create the Turbo C
  15279.          integrated environments bar menu:
  15280.  
  15281.  
  15282.            BAR_MENU_ENTRY bar_items[] = {
  15283.                        "File",       1,4, 'F',0,NULLFN,
  15284.                        "Edit",       1,10,'E',0,menu_func,
  15285.                        "Run",        1,17,'R',0,NULLFN,
  15286.                        "Compile",    1,23,'C',0,NULLFN,
  15287.                        "Project",    1,33,'P',0,NULLFN,
  15288.                        "Options",    1,43,'O',0,NULLFN,
  15289.                        "Debug",      1,53,'D',0,NULLFN,
  15290.                        "Break/watch",1,61,'B',0,NULLFN,
  15291.                                  CWL_NULL};
  15292.  
  15293.          In the above example, All of the entries have a NULLFN
  15294.          function pointer except for the "Edit" entry.  The entries
  15295.          with NULLFN function pointers will have popup windows
  15296.          displayed under them when they are selected.  The "Edit"
  15297.          option will not have a popup menu displayed under it.
  15298.          Instead, the menu_func() function is performed instead when
  15299.          "Edit" is chosen.
  15300.  
  15301.  
  15302.          Step 2) is as described in the Popup windows section.
  15303.  
  15304.  
  15305.  
  15306.  
  15307.          Page 241          The C Window Library               Page 241
  15308.  
  15309.          Step 3) can be done as follows:
  15310.  
  15311.  
  15312.  
  15313.          POPUP_MENU_PTR popup_list[8];
  15314.  
  15315.          main() {
  15316.          /* ... */
  15317.  
  15318.          popup_list[0] = PopupCreateMenu(/*..argument list..*/);
  15319.          popup_list[1] = (POPUP_MENU_PTR)0; /* No popup, so value
  15320.                                                must be NULL */
  15321.          popup_list[2] = PopupCreateMenu(/*..argument list..*/);
  15322.          popup_list[3] = PopupCreateMenu(/*..argument list..*/);
  15323.          popup_list[4] = PopupCreateMenu(/*..argument list..*/);
  15324.          popup_list[5] = PopupCreateMenu(/*..argument list..*/);
  15325.          popup_list[6] = PopupCreateMenu(/*..argument list..*/);
  15326.          popup_list[7] = PopupCreateMenu(/*..argument list..*/);
  15327.  
  15328.  
  15329.          The above example shows each element of popup_list is
  15330.          assigned to the return value of PopupCreateMenu(), except for
  15331.          popup_list[1].  Note that popup_list[1] is a null
  15332.          POPUP_MENU_PTR.  Here is the reason.  Let's say that there is
  15333.          an option on the bar menu that DOES NOT have a popup menu
  15334.          associated with it.  In other words, it is just a single
  15335.          function option, and no sub-functions are possible.  The
  15336.          entry in the array of POPUP_MENU_PTR's that will correspond
  15337.          to the position of where there is no popup menu should be
  15338.          NULL.  The above example shows that the second POPUP_MENU_PTR
  15339.          is non-existent (matches with the BAR_MENU_ENTRY called
  15340.          "Edit", which is the second bar entry).
  15341.  
  15342.          Once the bar menu and popup menus are created, you can set
  15343.          options by calling the BarSetOptions() or the
  15344.          PopupSetOptions() function, assign menu keys using the
  15345.          BarAssignKeys() or PopupAssignKeys() functions, etc. just as
  15346.          described earlier in this manual.  Remember that a pulldown
  15347.          menu just incorporates all of your menus into one manageable
  15348.          entity.
  15349.  
  15350.  
  15351.  
  15352.          The PulldownCreateMenu() function
  15353.          ---------------------------------
  15354.  
  15355.          The next step (Step 4) is done by calling the
  15356.          PulldownCreateMenu() function.  This function integrates the
  15357.          bar menu and the array of popup menus in a single unit.  A
  15358.          pointer to this unit is returned.  This pointer is declared
  15359.          as a PULLDOWN_MENU_PTR.  The prototype form the
  15360.          PulldownCreateMenu() function is as follows:
  15361.  
  15362.          PULLDOWN_MENU_PTR PulldownCreateMenu(POPUP_MENU_PTR popups[],
  15363.                                               BAR_MENU_PTR bar,
  15364.  
  15365.  
  15366.  
  15367.          Page 242          The C Window Library               Page 242
  15368.  
  15369.                                               int adjust)
  15370.  
  15371.          The first argument is a pointer to an array of
  15372.          POPUP_MENU_PTR's.  In the above example, the second argument
  15373.          is the BAR_MENU_PTR.  Here is an example of how to use the
  15374.          PulldownCreateMenu() function:
  15375.  
  15376.          #include "menu.h"
  15377.  
  15378.          BAR_MENU_ENTRY bar_items[] = {
  15379.                        "File",       1,4, 'F',0,NULLFN,
  15380.                        "Edit",       1,10,'E',0,menu_func,
  15381.                        "Run",        1,17,'R',0,NULLFN,
  15382.                        "Compile",    1,23,'C',0,NULLFN,
  15383.                        "Project",    1,33,'P',0,NULLFN,
  15384.                        "Options",    1,43,'O',0,NULLFN,
  15385.                        "Debug",      1,53,'D',0,NULLFN,
  15386.                        "Break/watch",1,61,'B',0,NULLFN,
  15387.                                  CWL_NULL};
  15388.  
  15389.  
  15390.          POPOP_MENU_ENTRY p1[] = {
  15391.                                  /* Popup entries */,
  15392.                                  CWL_NULL,0 };
  15393.  
  15394.          POPUP_MENU_ENTRY p2[] = POPUP_NULL_ENTRY; /* This constant
  15395.                                                       defines an empty
  15396.                                                   POPUP_MENU_ENTRY  */
  15397.  
  15398.          POPUP_MENU_ENTRY p3[] = {
  15399.                                  /* More popup entries */
  15400.                                CWL_NULL, 0 };
  15401.  
  15402.          POPUP_MENU_ENTRY p4[] = {
  15403.                                  /* More popup entries */
  15404.                                CWL_NULL, 0 };
  15405.  
  15406.  
  15407.          POPUP_MENU_ENTRY p5[] = {
  15408.                                  /* More popup entries */
  15409.                                CWL_NULL, 0 };
  15410.  
  15411.          POPUP_MENU_ENTRY p6[] = {
  15412.                                  /* More popup entries */
  15413.                                CWL_NULL, 0 };
  15414.  
  15415.          POPUP_MENU_ENTRY p7[] = {
  15416.                                  /* More popup entries */
  15417.                                CWL_NULL, 0 };
  15418.  
  15419.          POPUP_MENU_ENTRY p7[] = {
  15420.                                  /* More popup entries */
  15421.                                CWL_NULL, 0 };
  15422.  
  15423.          POPUP_MENU_PTR popup_list[8];
  15424.  
  15425.  
  15426.  
  15427.          Page 243          The C Window Library               Page 243
  15428.  
  15429.  
  15430.  
  15431.          BAR_MENU_PTR bar;
  15432.  
  15433.          PULLDOWN_MENU_PTR pull;
  15434.  
  15435.          main()
  15436.          {
  15437.            int i;
  15438.            WindowInitializeSystem();
  15439.            WindowSaveInitial(0);
  15440.            bar = BarCreateMenu(bar_items, { other arguments } );
  15441.  
  15442.            popup_list[0] = PopupCreateMenu(p1, { other arguments } );
  15443.            popup_list[1] = p2;
  15444.            popup_list[2] = PopupCreateMenu(p3, { other arguments } );
  15445.            popup_list[3] = PopupCreateMenu(p4, { other arguments } );
  15446.            popup_list[4] = PopupCreateMenu(p5, { other arguments } );
  15447.            popup_list[5] = PopupCreateMenu(p6, { other arguments } );
  15448.            popup_list[6] = PopupCreateMenu(p7, { other arguments } );
  15449.            popup_list[7] = PopupCreateMenu(p8, { other arguments } );
  15450.  
  15451.            pull = PulldownCreateMenu(popup_list,bar,1);
  15452.            {...}
  15453.          }
  15454.  
  15455.          In the above example, bar is a BAR_MENU_PTR, p1, p2, p3, p4,
  15456.          etc. are all lists of POPUP_MENU_ENTRY's.  The array of
  15457.          POPUP_MENU_PTR's is called popup_list, and the
  15458.          PULLDOWN_MENU_PTR is called pull.  Please note the use of the
  15459.          POPUP_NULL_ENTRY constant.  Use this constant when
  15460.          initializing a POPUP_MENU_ENTRY list to no items.
  15461.  
  15462.          The bar menu is initialized by calling BarCreateMenu() using
  15463.          bar_items as the list of BAR_MENU_ENTRY's.  The
  15464.          PopupCreateMenu() is called for each member of the popup_list
  15465.          array.  Note that the popup_list[1] is assigned a null
  15466.          POPUP_MENU_PTR.  This indicates that there is no popup menu
  15467.          for the second bar item ("Edit").  Even though it is not
  15468.          shown, you should check to see if BarCreateMenu() and all of
  15469.          the PopupCreateMenu() function calls returned without error.
  15470.  
  15471.          The call to PulldownCreateMenu() is done with the first
  15472.          argument being the the pointer to the array of
  15473.          POPUP_MENU_PTR's, namely popup_list.  The second argument is
  15474.          the BAR_MENU_PTR bar, and the last argument is discussed in
  15475.          the next section.
  15476.  
  15477.  
  15478.  
  15479.          Automatic Adjustment of Popup Windows
  15480.          -------------------------------------
  15481.  
  15482.          The last argument to PulldownCreateMenu() will inform the
  15483.          menu manager to adjust all the popup menu window positions,
  15484.  
  15485.  
  15486.  
  15487.          Page 244          The C Window Library               Page 244
  15488.  
  15489.          so that they fit neatly under the bar menu.  If the adjust
  15490.          argument in PulldownCreateMenu() is a 1, the previous
  15491.          (row,col) positions of each popup menu window is ignored
  15492.          (Arguments 3 and 4 of PopupCreateMenu()), and the menu
  15493.          manager decides where the popup window should be placed on
  15494.          the screen.  Otherwise, if adjust is 0, the previous values
  15495.          of the (row,col) position of the popup menu is used.
  15496.  
  15497.          Here is how the menu manager decides where the popup window
  15498.          should be placed:
  15499.  
  15500.          a)  The first attempt tries to place the left hand corner of
  15501.              the popup window under the first character of the option
  15502.              name in the bar menu.  If the column on the screen where
  15503.              we have placed the popup window, plus the popup windows
  15504.              width does not exceed the width of the bar, then we have
  15505.              found a "good" position for the popup window, if not then
  15506.              do step b).
  15507.  
  15508.          b)  We place the upper right hand corner of the popup window
  15509.              underneath the last column of the bar menu's window.  If
  15510.              the upper left-hand corner of the popup window can be
  15511.              placed in a screen column greater than or equal to 1,
  15512.              then we have found the "good" position.  If the upper
  15513.              left-hand corner cannot be placed in column 1 then do
  15514.              step c).
  15515.  
  15516.          c)  Place the upper left hand corner of the popup window at
  15517.              the first column of the bar menu window.  If this does
  15518.              not work then do step d).
  15519.  
  15520.          d)  place the popup window in column 1 of the screen.
  15521.  
  15522.          Here are a few examples of the above scenarios:
  15523.  
  15524.          1)
  15525.          -------------------------------------------------------------
  15526.          |  File      Edit      Compile      Options    Project      |
  15527.          |                                                           |
  15528.          ------------------------------------------------------------
  15529.            |            |
  15530.            |Condition a)|
  15531.            |  worked!   |
  15532.            |            |
  15533.            |------------|
  15534.  
  15535.  
  15536.  
  15537.  
  15538.  
  15539.  
  15540.  
  15541.  
  15542.  
  15543.  
  15544.  
  15545.  
  15546.  
  15547.          Page 245          The C Window Library               Page 245
  15548.  
  15549.          2a)
  15550.          ----------------------------------------------------
  15551.          |  File   Edit   Compile   Options    Project      |
  15552.          |                                                  |
  15553.          ------------------------------------------------------------
  15554.                                    |                                |
  15555.                                    |  Too wide! option a) failed!   |
  15556.                                    |                                |
  15557.                                    |         Try option b)          |
  15558.                                    |                                |
  15559.                                    |--------------------------------|
  15560.  
  15561.          2b)
  15562.  
  15563.          -------------------------------------------------------------
  15564.          |  File      Edit      Compile      Options    Project      |
  15565.          |                                                           |
  15566.          -------------------------------------------------------------
  15567.                                     |                                |
  15568.                                     |       option b) worked!        |
  15569.                                     |                                |
  15570.                                     |--------------------------------|
  15571.  
  15572.  
  15573.          In the first example, 1), the assumption is that the menu
  15574.          manager tries to place a popup window underneath the "File"
  15575.          in the bar menu.  It satisfies condition a), so we have found
  15576.          a good position.
  15577.  
  15578.          In the second example, 2a), the assumption is that the menu
  15579.          manager is trying to place a popup window under the "Compile"
  15580.          in the bar menu.   The first attempt fails because the popup
  15581.          window is too wide to be contained entirely in the bar menu.
  15582.          We then try again to see if condition b) can be satisfied.
  15583.          Example 2b) shows that we can place the popup window
  15584.          according to condition b), and we have found a good
  15585.          condition.
  15586.  
  15587.          The other conditions, c) and d) should be self-explanatory at
  15588.          this point.
  15589.  
  15590.          Remember, if you do not like the way the menu manager selects
  15591.          the window position, you can either
  15592.  
  15593.          a)  specify the row and column positions of each popup menu
  15594.              window yourself when calling PopupCreateMenu(), and then
  15595.              calling PulldownCreateMenu() with a 0 (no adjustment) as
  15596.              the third argument or
  15597.  
  15598.          b)  Let the menu manager decide where to put the windows, and
  15599.              then adjust the positions yourself by calling
  15600.              WindowMove().
  15601.  
  15602.  
  15603.  
  15604.  
  15605.  
  15606.  
  15607.          Page 246          The C Window Library               Page 246
  15608.  
  15609.          Return values for PulldownCreateMenu()
  15610.          --------------------------------------
  15611.  
  15612.          If there is no error, PulldownCreateMenu() returns a valid
  15613.          PULLDOWN_MENU_PTR.
  15614.  
  15615.          If there is an error, PulldownCreateMenu() returns a null
  15616.          PULLDOWN_MENU_PTR.
  15617.  
  15618.          Here are the possible reasons why an error has occurred:
  15619.  
  15620.          1) There was not enough memory to allocate for the
  15621.             PULLDOWN_MENU_PTR or its internal data structures.
  15622.  
  15623.          2) The window for the bar menu did not exist.
  15624.  
  15625.          The first error results from a lack of heap memory.  If this
  15626.          error occurs, the global integer window_error_code will be
  15627.          set to NO_HEAP_MEM.
  15628.  
  15629.          If the second error occurs, this is an indication that the
  15630.          BAR_MENU_PTR was not created properly.  Check the return
  15631.          values for BarCreateMenu() if this happens.  The
  15632.          window_error_code is set to BAD_WINDOW if this error occurs.
  15633.  
  15634.          There is no check to see if the POPUP_MENU_PTR's are valid.
  15635.          It is conceivable that there may be some entries on the bar
  15636.          that do not have popup menu's under them.  Therefore no check
  15637.          can be made for valid POPUP_WINDOW_PTR's.  It is the
  15638.          programmer's responsibility to check for invalid
  15639.          POPUP_MENU_PTR's when creating the popup menus.
  15640.  
  15641.  
  15642.  
  15643.  
  15644.  
  15645.  
  15646.  
  15647.  
  15648.  
  15649.  
  15650.  
  15651.  
  15652.  
  15653.  
  15654.  
  15655.  
  15656.  
  15657.  
  15658.  
  15659.  
  15660.  
  15661.  
  15662.  
  15663.  
  15664.  
  15665.  
  15666.  
  15667.          Page 247          The C Window Library               Page 247
  15668.  
  15669.                     SELECTING FROM PULLDOWN MENUS
  15670.                     -----------------------------
  15671.  
  15672.  
  15673.          The PulldownSelectMenu() function
  15674.          ---------------------------------
  15675.  
  15676.  
  15677.          The PulldownSelectMenu() allows selection from a pulldown
  15678.          menu.  This function has 6 arguments.  The prototype to this
  15679.          function is as follows:
  15680.  
  15681.          int PulldownSelectMenu(PULLDOWN_MENU_PTR pull, int barrank,
  15682.                                 unsigned barstart, int *poprank,
  15683.                                 unsigned *popstart, int imm)
  15684.  
  15685.          The first argument is a pointer to the PULLDOWN_MENU_PTR.
  15686.          The second argument is the window rank of the bar menu
  15687.          window.  The third argument is the menu option where the bar
  15688.          menu should start beginning processing.  If the option is
  15689.          invalid or unavailable, the starting entry is the first
  15690.          available entry or the first entry if the BAROVERRIDE option
  15691.          is on for the bar menu.
  15692.  
  15693.          The fourth argument is an array of window ranks for each
  15694.          popup menu's window.  This array will correspond to each of
  15695.          the popup menu's windows, including null popup menus.
  15696.  
  15697.          Example:
  15698.                int ranks[] = {1,1,1,1,1,1,1,1};
  15699.                unsigned start[] = {1,1,1,1,1,1,1,1};
  15700.  
  15701.                main() {
  15702.                /* ... */
  15703.                  PulldownSelectMenu(pull,1,1,ranks,start,1);
  15704.  
  15705.                }
  15706.  
  15707.  
  15708.          The fifth argument is an array of starting entry numbers for
  15709.          each popup menu.  This array will correspond to each of the
  15710.          popup menus, including NULL popup menus.  The previous
  15711.          example illustrates how this could be done.
  15712.  
  15713.  
  15714.  
  15715.          Immediate Mode
  15716.          --------------
  15717.  
  15718.          The last argument to PulldownSelectMenu() determines whether
  15719.          the menu will start in immediate mode.  Immediate mode will
  15720.          display the bar menu, and will also display the popup menu
  15721.          defined for the bar option.  If immediate mode is desired,
  15722.          the last argument is a 1, otherwise it is a 0.
  15723.  
  15724.  
  15725.  
  15726.  
  15727.          Page 248          The C Window Library               Page 248
  15728.  
  15729.          Values passed to the selected menu function
  15730.          -------------------------------------------
  15731.  
  15732.          When a selection is made, the menu manager will call the
  15733.          function defined for the selection, and pass five arguments
  15734.          to this function.  The first argument passed is the
  15735.          PULLDOWN_MENU_PTR of the current pulldown menu.  The second
  15736.          argument is the BAR_MENU_PTR of the pulldown menu.  The third
  15737.          argument is the POPUP_MENU_PTR of the selected entry.  If
  15738.          there is no popup menu,  the value passed for this argument
  15739.          is a NULL pointer.  The fourth argument is the number of the
  15740.          item selected on the bar menu.  The fifth argument is the
  15741.          number of the item selected on the popup menu.
  15742.  
  15743.  
  15744.  
  15745.          Values returned to the menu manager
  15746.          -----------------------------------
  15747.  
  15748.          Your function must return a value back to the menu manager.
  15749.          There are two possible return values, PULLDOWN_EXIT and
  15750.          PULLDOWN_CONTINUE.
  15751.  
  15752.          The PULLDOWN_EXIT return value will cause the menu manager to
  15753.          close both the popup menu window (if one was displayed), and
  15754.          the bar menu.  Then control is returned back to the function
  15755.          that called PulldownSelectMenu().
  15756.  
  15757.          The PULLDOWN_CONTINUE return value will cause the menu
  15758.          manager to continue processing the pulldown menu without
  15759.          closing the popup window (if one was displayed).
  15760.  
  15761.  
  15762.          If the return value is not one of the ones mentioned above,
  15763.          PULLDOWN_CONTINUE is assumed.
  15764.  
  15765.  
  15766.  
  15767.          Return Values for PulldownSelectMenu()
  15768.          --------------------------------------
  15769.  
  15770.          If there are no errors, PulldownSelectMenu() returns NO_ERROR.
  15771.  
  15772.          If the bar menu window does not exist, PulldownSelectMenu()
  15773.          immediately returns with BAD_WINDOW.
  15774.  
  15775.          If the bar menu window is not open, PulldownSelectMenu()
  15776.          immediately returns with WINDOW_NOT_OPEN.
  15777.  
  15778.  
  15779.  
  15780.  
  15781.  
  15782.  
  15783.  
  15784.  
  15785.  
  15786.  
  15787.          Page 249          The C Window Library               Page 249
  15788.  
  15789.                      REDEFINING KEY DEFINITIONS
  15790.                      --------------------------
  15791.  
  15792.          The bar menu key definitions are invoked when the pulldown
  15793.          menu is at the bar menu level.  The popup menu keys are
  15794.          invoked when the pulldown menu is at the popup menu level.
  15795.  
  15796.          If the bar option does not have a popup menu associated with
  15797.          it, the bar menu keys are always used.
  15798.  
  15799.  
  15800.  
  15801.  
  15802.  
  15803.  
  15804.  
  15805.  
  15806.  
  15807.  
  15808.  
  15809.  
  15810.  
  15811.  
  15812.  
  15813.  
  15814.  
  15815.  
  15816.  
  15817.  
  15818.  
  15819.  
  15820.  
  15821.  
  15822.  
  15823.  
  15824.  
  15825.  
  15826.  
  15827.  
  15828.  
  15829.  
  15830.  
  15831.  
  15832.  
  15833.  
  15834.  
  15835.  
  15836.  
  15837.  
  15838.  
  15839.  
  15840.  
  15841.  
  15842.  
  15843.  
  15844.  
  15845.  
  15846.  
  15847.          Page 250          The C Window Library               Page 250
  15848.  
  15849.              REDEFINING KEY DEFINITIONS FOR POPUP MENUS
  15850.              ------------------------------------------
  15851.  
  15852.          Setting Popup Menu Global Key Definitions
  15853.          -----------------------------------------
  15854.  
  15855.          In the previous sections on popup menus, there was a global
  15856.          array of key definitions used for popup menus.  Recall that
  15857.          there were 3 key definitions that were not assigned.  These
  15858.          definitions were POPUP_RIGHTKEY, POPUP_LEFTKEY, and
  15859.          POPUP_PULLDOWN_QUIT.  When a popup menu is incorporated into
  15860.          a pulldown menu (after the PulldownCreateMenu() is called),
  15861.          the global array popup_key_definition is assigned the default
  15862.          values for these definitions.  Here are the default values
  15863.          for the popup portion of the pulldown menu:
  15864.  
  15865.  
  15866.            Function                      Key        Constant
  15867.            --------                      ---         ------
  15868.          Move highlight bar up       Up Arrow    POPUP_UPKEY
  15869.          Move highlight bar down     Down Arrow  POPUP_DOWNKEY
  15870.          Accept Menu Choice          Enter       POPUP_ACCEPTKEY
  15871.          Escape Pop-up menu          Escape      POPUP_QUITKEY
  15872.          Move To First Menu Item     Home        POPUP_HOMEKEY
  15873.          Move to Last Menu Item      End         POPUP_ENDKEY
  15874.          Move To Next Popup Menu     Right Arrow POPUP_RIGHTKEY
  15875.          Move to Previous Popup Menu Left Arrow  POPUP_LEFTKEY
  15876.          Escape Pulldown Menu        Unassigned  POPUP_PULLDOWN_QUITKEY
  15877.  
  15878.  
  15879.          The global array popup_key_definition contains the values of
  15880.          the default popup menu key definitions.  The names under the
  15881.          Constant heading are the offsets in the popup_key_definition
  15882.          array of where the key value for the function is defined.
  15883.          For instance, the value for the "Move highlight bar up"
  15884.          function is located at popup_key_definition[POPUP_UPKEY].
  15885.          You can change the values in popup_key_definition at any
  15886.          time, but make sure that a definition for "Escape Pop-up
  15887.          menu" and/or "Escape Pulldown Menu" always exists, and that
  15888.          there are no duplicate definitions (i.e.  the "Move highlight
  15889.          bar up" key definition is the same as the "Move highlight bar
  15890.          down" key definition).  When defining new key values, you
  15891.          should use the values defined in the keycodes.h header file
  15892.          for non-ascii keys.
  15893.  
  15894.          Also note that popup_key_definition[POPUP_PULLDOWN_QUITKEY]
  15895.          is not assigned.  Since the key that is usually used to quit
  15896.          a pulldown menu is the Escape (ESC) key, and this definition
  15897.          conflicts with the "Escape Popup menu", it is better to let
  15898.          the programmer change the definition explicitly.
  15899.  
  15900.  
  15901.  
  15902.  
  15903.  
  15904.  
  15905.  
  15906.  
  15907.          Page 251          The C Window Library               Page 251
  15908.  
  15909.  
  15910.          Setting Popup Menu Local Definitions
  15911.          ------------------------------------
  15912.  
  15913.          You can use the PopupAssignKeys() function explained in the
  15914.          REDEFINING MENU KEYS section to redefine the popup menu keys
  15915.          for each popup menu.
  15916.  
  15917.  
  15918.  
  15919.  
  15920.  
  15921.  
  15922.  
  15923.  
  15924.  
  15925.  
  15926.  
  15927.  
  15928.  
  15929.  
  15930.  
  15931.  
  15932.  
  15933.  
  15934.  
  15935.  
  15936.  
  15937.  
  15938.  
  15939.  
  15940.  
  15941.  
  15942.  
  15943.  
  15944.  
  15945.  
  15946.  
  15947.  
  15948.  
  15949.  
  15950.  
  15951.  
  15952.  
  15953.  
  15954.  
  15955.  
  15956.  
  15957.  
  15958.  
  15959.  
  15960.  
  15961.  
  15962.  
  15963.  
  15964.  
  15965.  
  15966.  
  15967.          Page 252          The C Window Library               Page 252
  15968.  
  15969.              REDEFINING KEY DEFINITIONS FOR THE BAR MENU
  15970.              -------------------------------------------
  15971.  
  15972.  
  15973.          Setting bar menu global key definitions
  15974.          ---------------------------------------
  15975.  
  15976.          You can redefine the keys used to control moving the
  15977.          highlight bar, accepting the menu choice, and exiting from
  15978.          the menu.  Here is a list of the default key mapping:
  15979.  
  15980.               Function                  Key          Constant
  15981.               --------                  ---           ------
  15982.             Move highlight bar right  Up Arrow     BAR_RIGHTKEY
  15983.             Move highlight bar left   Down Arrow   BAR_LEFTKEY
  15984.             Accept Menu Choice        Enter        BAR_ACCEPTKEY
  15985.             Escape Bar menu or        Escape       BAR_QUITKEY
  15986.             Escape Pulldown Menu
  15987.             Move To First Menu Item   Home         BAR_HOMEKEY
  15988.             Move to Last Menu Item    End          BAR_ENDKEY
  15989.  
  15990.  
  15991.  
  15992.          The global array bar_key_definition contains the values of
  15993.          the default bar menu key definitions.  The names under the
  15994.          Constant heading are the offsets in the bar_key_definition
  15995.          array of where the key value for the function is defined.
  15996.          For instance, the value for the "Move highlight bar up"
  15997.          function is located at bar_key_definition[BAR_RIGHTKEY].  You
  15998.          can change the values in bar_key_definition at any time, but
  15999.          make sure that a definition for "Escape Bar menu" always
  16000.          exists, and that there are no duplicate definitions (i.e.
  16001.          the "Move highlight bar up" key definition is the same as the
  16002.          "Move highlight bar down" key definition).  When defining new
  16003.          key values, you should use the values defined in the
  16004.          keycodes.h header file for non-ascii keys.
  16005.  
  16006.          Note that "Escape Bar Menu" will also escape the pulldown
  16007.          menu.
  16008.  
  16009.  
  16010.  
  16011.  
  16012.          Setting Bar Menu Local definitions
  16013.          ----------------------------------
  16014.  
  16015.          You can use the BarAssignKeys() function to redefine the bar
  16016.          menu keys.
  16017.  
  16018.  
  16019.  
  16020.  
  16021.  
  16022.  
  16023.  
  16024.  
  16025.  
  16026.  
  16027.          Page 253          The C Window Library               Page 253
  16028.  
  16029.                 PROCESSING UNDEFINED POPUP MENU KEYS
  16030.                 ------------------------------------
  16031.  
  16032.          Processing undefined keys is the same for regular popup
  16033.          menus, except that there are 3 new return values that can be
  16034.          used for popup menus that are incorporated in pulldown menus.
  16035.  
  16036.          The popup_undef_key function pointer acts the same way as
  16037.          described previously.  Here are the possible values that the
  16038.          function pointed to by popup_undef_key must return:
  16039.  
  16040.  
  16041.            Return                         Action to
  16042.            Value                            Take
  16043.            ------                         ---------
  16044.           POPUP_CONTINUE          No Action. Continue processing the
  16045.                                   popup menu.
  16046.  
  16047.           POPUP_MOVE_UP           Move the highlight bar up.
  16048.  
  16049.           POPUP_MOVE_DOWN         Move the highlight bar down.
  16050.  
  16051.           POPUP_DO_CHOICE         Accept and invoke menu entry
  16052.                                   assigned to *choice.
  16053.  
  16054.           POPUP_MOVE_CONTINUE     Move the highlight bar to menu
  16055.                                   entry assigned to *choice and
  16056.                                   continue processing menu.
  16057.  
  16058.           POPUP_ESCAPE            Escape the popup menu.
  16059.  
  16060.           POPUP_MOVE_HOME         Move highlight to first available
  16061.                                   menu entry.
  16062.  
  16063.           POPUP_MOVE_END          Move highlight to last available
  16064.                                   menu entry.
  16065.  
  16066.           POPUP_MOVE_PAGEUP       Scroll the entries in the popup
  16067.                                   window up by one "page" (a page is
  16068.                                   the current height of the popup
  16069.                                   window).
  16070.  
  16071.           POPUP_MOVE_PAGEDOWN     Scroll the entries in the popup
  16072.                                   window down by one "page" (a page is
  16073.                                   the current height of the popup
  16074.                                   window).
  16075.  
  16076.           POPUP_MOVE_LEFT         Move to next popup menu.
  16077.  
  16078.           POPUP_MOVE_RIGHT        Move to previous popup menu.
  16079.  
  16080.           POPUP_PULLDOWN_QUIT     Escape pulldown menu
  16081.  
  16082.          Please note the new return values POPUP_MOVE_LEFT,
  16083.          POPUP_MOVE_RIGHT, and POPUP_PULLDOWN_QUIT.
  16084.  
  16085.  
  16086.  
  16087.          Page 254          The C Window Library               Page 254
  16088.  
  16089.                  PROCESSING UNDEFINED BAR MENU KEYS
  16090.                  ----------------------------------
  16091.  
  16092.          Here are the return values that the function pointed to by
  16093.          bar_undef_key must return.
  16094.  
  16095.            Return                         Action to
  16096.            Value                            Take
  16097.            ------                         ---------
  16098.           BAR_CONTINUE          No Action. Continue processing the bar
  16099.                                 menu.
  16100.  
  16101.           BAR_DO_CHOICE         Accept and invoke menu entry assigned
  16102.                                 to *choice, or display popup menu
  16103.                                 underneath bar entry.
  16104.  
  16105.           BAR_MOVE_CONTINUE     Move the highlight bar to menu entry
  16106.                                 assigned to *choice and continue
  16107.                                 processing menu.
  16108.  
  16109.           BAR_ESCAPE            Escape the bar menu (or pulldown menu).
  16110.  
  16111.           BAR_MOVE_LEFT         Move to next bar menu entry.
  16112.  
  16113.           BAR_MOVE_RIGHT        Move to previous bar menu entry.
  16114.  
  16115.           BAR_MOVE_HOME         Move highlight to first available menu
  16116.                                 entry.
  16117.  
  16118.           BAR_MOVE_END          Move highlight to last available menu
  16119.                                 entry.
  16120.  
  16121.  
  16122.          Please note that BAR_DO_CHOICE will either do the function
  16123.          assigned to the bar entry assigned to *choice, or display the
  16124.          popup menu underneath the bar menu entry assigned to *choice.
  16125.  
  16126.  
  16127.  
  16128.  
  16129.  
  16130.  
  16131.  
  16132.  
  16133.  
  16134.  
  16135.  
  16136.  
  16137.  
  16138.  
  16139.  
  16140.  
  16141.  
  16142.  
  16143.  
  16144.  
  16145.  
  16146.  
  16147.          Page 255          The C Window Library               Page 255
  16148.  
  16149.                      DISPOSING OF PULLDOWN MENUS
  16150.                      ---------------------------
  16151.  
  16152.          There are two functions that are used to dispose of pulldown
  16153.          menus.  The first is the PulldownMenuFree() function.
  16154.  
  16155.  
  16156.  
  16157.          The PulldownMenuFree() function
  16158.          -------------------------------
  16159.  
  16160.          The PulldownMenuFree() function disposes of the
  16161.          PULLDOWN_MENU_PTR and returns memory allocated back to the
  16162.          heap.  The bar menu and the popup menus associated with the
  16163.          pulldown menu remain intact.
  16164.  
  16165.          Here is a prototype of the call to PulldownMenuFree():
  16166.  
  16167.              int PulldownMenuFree(PULLDOWN_MENU_PTR pull)
  16168.  
  16169.  
  16170.  
  16171.  
  16172.          The PulldownMenuFreeAll() function
  16173.          ----------------------------------
  16174.  
  16175.  
  16176.          To dispose of the pulldown menu, the bar menu, and all of the
  16177.          popup menus, use the PulldownMenuFreeAll() function.  Here is
  16178.          a prototype:
  16179.  
  16180.                     int PulldownMenuFreeAll(PULLDOWN_MENU_PTR pull)
  16181.  
  16182.  
  16183.  
  16184.  
  16185.  
  16186.  
  16187.  
  16188.  
  16189.  
  16190.  
  16191.  
  16192.  
  16193.  
  16194.  
  16195.  
  16196.  
  16197.  
  16198.  
  16199.  
  16200.  
  16201.  
  16202.  
  16203.  
  16204.  
  16205.  
  16206.  
  16207.          Page 256          The C Window Library               Page 256
  16208.  
  16209.                       SUMMARY OF PULLDOWN MENUS
  16210.                       -------------------------
  16211.  
  16212.          A pulldown menu is:
  16213.  
  16214.            1)  Made up of a bar menu and popup menus.
  16215.  
  16216.  
  16217.            2)  Consists of two levels, namely the bar menu level and
  16218.                the popup menu level.
  16219.  
  16220.  
  16221.            3)  The bar menu level uses the bar menu key definitions,
  16222.                while the popup menu level uses the popup menu key
  16223.                definitions.
  16224.  
  16225.            4)  The popup menus are initialized by using an array of
  16226.                POPUP_MENU_PTR's.  The order of where the popup menus
  16227.                are defined in this array corresponds to each of the
  16228.                bar menu options.
  16229.  
  16230.            5)  A bar menu option may or may not have a popup menu
  16231.                defined for it.
  16232.  
  16233.            6)  When initializing a pulldown menu, you can allow the
  16234.                menu manager to position the popup windows under the
  16235.                bar menu, or you can specify your own positions on the
  16236.                screen for the popup menu windows.
  16237.  
  16238.            7)  When the menu manager calls the user written function
  16239.                the PULLDOWN_MENU_PTR, BAR_MENU_PTR, POPUP_MENU_PTR,
  16240.                the number of the bar entry selected, and the number of
  16241.                the popup selection are passed to the user function.
  16242.                If there is no popup menu, the POPUP_MENU_PTR passed is
  16243.                a null, and the popup selection number is 0.
  16244.  
  16245.            8)  You can open a pulldown menu from the bar level, or
  16246.                from the pull down level by calling
  16247.                PulldownSelectMenu().
  16248.  
  16249.            9)  You can close a pulldown menu in two ways:  by just
  16250.                disposing of the PULLDOWN_MENU_PTR by calling
  16251.                PulldownMenuFree(), or disposing of all menus used to
  16252.                create the pulldown menu by calling
  16253.                PulldownMenuFreeAll().
  16254.  
  16255.  
  16256.  
  16257.  
  16258.  
  16259.  
  16260.  
  16261.  
  16262.  
  16263.  
  16264.  
  16265.  
  16266.  
  16267.          Page 257          The C Window Library               Page 257
  16268.  
  16269.                    EXAMPLE OF PULLDOWN MENU SYSTEM
  16270.                    -------------------------------
  16271.  
  16272.          Here is an example of a pulldown menu system.  This program
  16273.          emulates the Turbo C integrated environment.
  16274.  
  16275.  
  16276.          #include "menu.h"
  16277.  
  16278.          #define BLACKONWHITE   CREATE_VIDEO_ATTRIBUTE(white,black)
  16279.  
  16280.  
  16281.          int menu_routine();
  16282.  
  16283.          POPUP_MENU_ENTRY menu_items1[] = {
  16284.                     " Load      F3",1,'L',F3,menu_routine,
  16285.                     " Pick  Alt-F3",2, 'P',ALTF3,menu_routine,
  16286.                     " New"         ,3, 'N',0,menu_routine,
  16287.                     " Save      F2",4, 'S',F2,menu_routine,
  16288.                     " Write to    ",5, 'W',0,menu_routine,
  16289.                     " Directory   ",6, 'D',0,menu_routine,
  16290.                     " Change Dir"  ,7, 'C',0,menu_routine,
  16291.                     " OS shell"    ,8, 'O',0,menu_routine,
  16292.                     " Quit  Alt-X"  ,9,'Q',ALTX,menu_routine,
  16293.                     CWL_NULL,0};
  16294.  
  16295.  
  16296.  
  16297.          POPUP_MENU_ENTRY menu_items3[] = {
  16298.               " Run             Ctrl-F9 ",1,'R',CTRLF9,menu_routine,
  16299.               " Program reset   Ctrl-F2 ",2,'P',CTRLF2,menu_routine,
  16300.               " Go to Cursor         F4 ",3,'G',F4,menu_routine,
  16301.               " Trace into           F7 ",4,'T',F7,menu_routine,
  16302.               " Step over            F8 ",5,'S',F8,menu_routine,
  16303.               " User screen      Alt-F5 ",6,'U',ALTF5,menu_routine,
  16304.               CWL_NULL,0};
  16305.  
  16306.  
  16307.          POPUP_MENU_ENTRY menu_items4[] = {
  16308.           " Compile to OBJ                   ",1,'C',0,menu_routine,
  16309.           " Make EXE file                    ",2,'M',0,menu_routine,
  16310.           " Link EXE file                    ",3,'L',0,menu_routine,
  16311.           " Build all                        ",4,'B',0,menu_routine,
  16312.           " Primary C file:                  ",5,'P',0,menu_routine,
  16313.           " Get info                         ",6,'G',0,menu_routine,
  16314.             CWL_NULL,0};
  16315.  
  16316.  
  16317.          POPUP_MENU_ENTRY menu_items5[] = {
  16318.           " Project Name                     ",1,'P',0,menu_routine,
  16319.           " Break make on                    ",2,'B',0,menu_routine,
  16320.           " Auto dependencies                ",3,'A',0,menu_routine,
  16321.           " Clear project                    ",4,'C',0,menu_routine,
  16322.           " Remove messages                  ",5,'R',0,menu_routine,
  16323.             CWL_NULL,0};
  16324.  
  16325.  
  16326.  
  16327.          Page 258          The C Window Library               Page 258
  16328.  
  16329.          POPUP_MENU_ENTRY menu_items6[] = {
  16330.           " Compiler          ",1,'C',0,menu_routine,
  16331.           " Linker            ",2,'L',0,menu_routine,
  16332.           " Environment       ",3,'E',0,menu_routine,
  16333.           " Directories       ",4,'D',0,menu_routine,
  16334.           " Arguments         ",5,'A',0,menu_routine,
  16335.           " Save Options      ",6,'S',0,menu_routine,
  16336.           " Retrieve options  ",7,'R',0,menu_routine,
  16337.             CWL_NULL,0};
  16338.  
  16339.  
  16340.          POPUP_MENU_ENTRY menu_items7[] = {
  16341.           " Evaluate    Ctrl-F4           ",1,'E',CTRLF4,menu_routine,
  16342.           " Call Stack  Ctrl-F3           ",2,'C',CTRLF3,menu_routine,
  16343.           " Find Function                 ",3,'F',0,menu_routine,
  16344.           " Refresh display               ",4,'R',0,menu_routine,
  16345.           " Display swapping     Smart    ",5,'D',0,menu_routine,
  16346.           " Source debugging              ",6,'S',0,menu_routine,
  16347.             CWL_NULL,0};
  16348.  
  16349.  
  16350.          POPUP_MENU_ENTRY menu_items8[] = {
  16351.          " Add watch           Ctrl-F7 ",1,'A',CTRLF7,menu_routine,
  16352.          " Delete watch                ",2,'D',0,menu_routine,
  16353.          " Edit Watch                  ",3,'E',0,menu_routine,
  16354.          " Remove all watches          ",4,'R',0,menu_routine,
  16355.          " Toggle breakpoint   Ctrl-F8 ",6,'T',CTRLF8,menu_routine,
  16356.          " Clear all breakpoints       ",7,'C',0,menu_routine,
  16357.          " View next breakpoint        ",8,'V',0,menu_routine,
  16358.            CWL_NULL,0};
  16359.  
  16360.  
  16361.          BAR_MENU_ENTRY bar_items[] = {
  16362.                      "File",1,4,'F',0,NULLFN,
  16363.                      "Edit",1,10,'E',0,menu_routine,
  16364.                      "Run",1,17,'R',0,NULLFN,
  16365.                      "Compile",1,23,'C',0,NULLFN,
  16366.                      "Project",1,33,'P',0,NULLFN,
  16367.                      "Options", 1,43,'O',0,NULLFN,
  16368.                      "Debug",1,53,'D',0,NULLFN,
  16369.                      "Break/watch",1,61,'B',0,NULLFN,
  16370.                                            CWL_NULL};
  16371.  
  16372.          POPUP_MENU_ENTRY  *pentry[] = {menu_items1,
  16373.                                         POPUP_NULL_ENTRY,
  16374.                                         menu_items3,
  16375.                                         menu_items4,
  16376.                                         menu_items5,
  16377.                                         menu_items6,
  16378.                                         menu_items7,
  16379.                                         menu_items8};
  16380.  
  16381.          unsigned menu_colors[5];    /* Menu colors */
  16382.          BAR_MENU_PTR bar;           /* Pointer to bar menu */
  16383.          POPUP_MENU_PTR popups[8];   /* Array of pointers to
  16384.  
  16385.  
  16386.  
  16387.          Page 259          The C Window Library               Page 259
  16388.  
  16389.                                         popup menus */
  16390.          PULLDOWN_MENU_PTR pull;     /* Pointer to pulldown menu */
  16391.  
  16392.          WPOINTER my_open();         /* Pointer to custom bar
  16393.                                         window open function */
  16394.          unsigned int popuprank[] = {1,1,1,1,1,1,1,1};  /* Ranks */
  16395.          int popupstart[] = {1,1,1,1,1,1,1,1}; /* Starting option
  16396.                                               for each popup menu */
  16397.          int height[] = {9,0,6,6,5,7,6,8}; /* height of each window */
  16398.  
  16399.          WPOINTER pw;  /* Misc. windows, not part of menu
  16400.                                                    system */
  16401.  
  16402.          char *line =
  16403.                  "─────────────────────────────"; /* Horizontal line */
  16404.  
  16405.  
  16406.          main()
  16407.          {
  16408.            int i;
  16409.            WindowInitializeSystem();
  16410.            WindowSaveInitial(0);
  16411.            pw = WindowInitialize(BORDER,5,10,70,5,BLACKONWHITE,
  16412.                                  BLACKONWHITE,SINGLEBOX);
  16413.            WindowOpen(pw);
  16414.           /* define colors */
  16415.            menu_colors[0] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16416.            menu_colors[1] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16417.            menu_colors[2] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  16418.            menu_colors[3] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  16419.            menu_colors[4] = CREATE_VIDEO_ATTRIBUTE(white,black);
  16420.  
  16421.            bar = BarCreateMenu(bar_items,menu_colors,6,1,
  16422.                                BARWRAP | BARSTATIC, my_open);
  16423.  
  16424.                         /* Now loop to create all popup menus
  16425.                  Be careful and assign NULL to the second popup menu */
  16426.  
  16427.            for (i=0; i<8; i++)       /* Loop for all popup menus */
  16428.            {
  16429.              if (pentry[i] != POPUP_NULL_ENTRY)  /* Skip over NULL */
  16430.              {
  16431.                popups[i] =
  16432.                PopupCreateMenu(pentry[i],
  16433.                                menu_colors,
  16434.                                  1,
  16435.                                  1,
  16436.                                  height[i],
  16437.                                  POPUPWRAP | POPUPSTATIC,
  16438.                                  WNULLFN,
  16439.                                  VWNULLFN);
  16440.              }
  16441.              else
  16442.                popups[i] = (POPUP_MENU_PTR)0;  /* Make this a null
  16443.                                                   POPUP_MENU_PTR */
  16444.  
  16445.  
  16446.  
  16447.          Page 260          The C Window Library               Page 260
  16448.  
  16449.            }  /* end for (i=0 ... */
  16450.  
  16451.            VirtualWriteString(POPUP_VIRTUAL_WINDOW(popups[7]),line,
  16452.                               5,1);
  16453.  
  16454.            /* hide 2nd and 3rd entries in */
  16455.            PopupMakeEntryUnavailable(popups[6],2);
  16456.            PopupMakeEntryUnavailable(popups[6],3);
  16457.  
  16458.            /* puit override option on number 6 */
  16459.            PopupSetOptions(popups[6],POPUPOVERRIDE,1);
  16460.  
  16461.            /* create pulldown menu */
  16462.            pull = PulldownCreateMenu(popups,bar,1);
  16463.  
  16464.            /* get the menu options */
  16465.            PulldownSelectMenu(pull,1,1,popuprank,popupstart,1);
  16466.  
  16467.            /* dispose of menu */
  16468.            PulldownMenuFree(pull);
  16469.          }
  16470.  
  16471.          int menu_routine(PULLDOWN_MENU_PTR p, BAR_MENU_PTR b,
  16472.                           POPUP_MENU_PTR pop,
  16473.                           unsigned int hs, unsigned int vs)
  16474.          {
  16475.            int ch;
  16476.            WindowClear(pw);
  16477.            WindowPrintf(pw,
  16478.                  "You have selected bar option %s\npopup option %s\n",
  16479.                    BAR_ENTRY_STRING(b,hs),POPUP_ENTRY_STRING(pop,vs));
  16480.            WindowWriteCenterString(pw,"Press Escape to Quit",3);
  16481.            WindowWriteCenterString(pw,
  16482.                                "Press any other key to continue...",4);
  16483.            WindowDisplay(pw,1,NOEFFECT);
  16484.            ch = GET_KEY();
  16485.            WindowHide(pw,NOEFFECT);
  16486.            if (ch == ESC)
  16487.              return PULLDOWN_EXIT;
  16488.            return PULLDOWN_CONTINUE;
  16489.          }
  16490.  
  16491.  
  16492.          WPOINTER my_open()  /* Custom window open function */
  16493.          {
  16494.            WPOINTER w;
  16495.            w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,
  16496.                                 BLACKONWHITE,"");
  16497.            WindowOpen(w);
  16498.            return w;
  16499.          }
  16500.  
  16501.  
  16502.  
  16503.  
  16504.  
  16505.  
  16506.  
  16507.          Page 261          The C Window Library               Page 261
  16508.  
  16509.                        MISCELLANEOUS FUNCTIONS
  16510.                        -----------------------
  16511.  
  16512.          There are other functions in The C Window Library that you
  16513.          can use without defining windows.
  16514.  
  16515.  
  16516.  
  16517.                   SETTING AND CHECKING VIDEO PAGES
  16518.                   --------------------------------
  16519.  
  16520.          The following functions sets and checks video pages.  Your
  16521.          video setup must support multiple video pages for the
  16522.          examples given in this section to work.  Please refer to page
  16523.          5 for a discussion of video adapters and the number of pages
  16524.          each will support.
  16525.  
  16526.  
  16527.  
  16528.          CheckVideoPage()
  16529.          ----------------
  16530.  
  16531.          This function checks to see if the video page is valid.  Here
  16532.          is the prototype:
  16533.  
  16534.  
  16535.                         int CheckVideoPage(int page)
  16536.  
  16537.          If page is valid, CheckVideoPage() returns NO_ERROR.  If it
  16538.          is not, the return value is INVALID_PAGE.
  16539.  
  16540.  
  16541.          Example:
  16542.  
  16543.  
  16544.          #include "window.h"
  16545.  
  16546.          main()
  16547.          {
  16548.            int i;
  16549.            WindowInitializeSystem();
  16550.            for (i=0;i<8;i++)
  16551.            {
  16552.              if (CheckVideoPage(i) == NO_ERROR)
  16553.                printf("\nValid video page #%d",i);
  16554.              else
  16555.                printf("\nInvalid video page #%d",i);
  16556.            }
  16557.          }
  16558.  
  16559.  
  16560.  
  16561.  
  16562.  
  16563.  
  16564.  
  16565.  
  16566.  
  16567.          Page 262          The C Window Library               Page 262
  16568.  
  16569.          SetActiveVideoPage() function
  16570.          -----------------------------
  16571.  
  16572.          The SetActiveVideoPage() function sets the active video page.
  16573.          Here is a prototype:
  16574.  
  16575.                   int SetActiveVideoPage(int page)
  16576.  
  16577.          Any windows initialized with WindowInitialize() will have its
  16578.          output directed to the current active video page on
  16579.          initialization.  This function DOES NOT change the visible
  16580.          display page.
  16581.  
  16582.          Example:
  16583.  
  16584.          #include "window.h"
  16585.          #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  16586.  
  16587.          WPOINTER w1, w2;
  16588.          main()
  16589.          {
  16590.            WindowInitializeSystem();
  16591.  
  16592.            /* Save Base Screen for video pages 0 and 1 */
  16593.            WindowSaveInitial(0);
  16594.            WindowSaveInitial(1);
  16595.  
  16596.            /* Set the active video page */
  16597.            SetActiveVideoPage(0);
  16598.            w1 = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  16599.            SetActiveVideoPage(1);
  16600.            w2 = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  16601.          }
  16602.  
  16603.          The above example shows two windows, w1 and w2, being open on
  16604.          different video pages.  Please note the two calls to
  16605.          WindowSaveInitial().  The first saves the base screen on
  16606.          video page 0, and the second call saves the initial screen on
  16607.          page 1.  The first call to SetActiveVideoPage() sets the
  16608.          active video page to page 0.  This is usually the active
  16609.          video page on startup.  Since the active page is 0, w1 is
  16610.          opened with page 0 as its video page.  The second call to
  16611.          SetActiveVideoPage() makes page 1 the active page, therefore
  16612.          w2 is initialized to send its output to video page 1.
  16613.  
  16614.          If there are no errors, SetActiveVideoPage() returns
  16615.          NO_ERROR.
  16616.  
  16617.          If there are errors, SetActiveVideoPage() returns
  16618.          INVALID_PAGE if the video page is invalid.
  16619.  
  16620.  
  16621.  
  16622.  
  16623.  
  16624.  
  16625.  
  16626.  
  16627.          Page 263          The C Window Library               Page 263
  16628.  
  16629.          SetVisibleVideoPage() function
  16630.          ------------------------------
  16631.  
  16632.          The SetVisibleVideoPage() function sets the visible video
  16633.          page.  Here is a prototype:
  16634.  
  16635.                   int SetVisibleVideoPage(int page)
  16636.  
  16637.          The visible video page is the page displayed on the screen.
  16638.  
  16639.  
  16640.          Example:
  16641.  
  16642.          #include "window.h"
  16643.          #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  16644.  
  16645.          WPOINTER w1,w2;
  16646.  
  16647.          main()
  16648.          {
  16649.            WindowInitializeSystem();
  16650.  
  16651.            /* Make sure video page is 0 */
  16652.            SetVisibleVideoPage(0);
  16653.            SetActiveVideoPage(0);
  16654.  
  16655.            /*Save Base screen for video pages 0 and 1 */
  16656.            WindowSaveInitial(0);
  16657.            WindowSaveInitial(1);
  16658.  
  16659.            /* Initialize Windows */
  16660.            w1 = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  16661.            SetActiveVideoPage(1);
  16662.            w2 = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  16663.            WindowOpen(w1);
  16664.            WindowOpen(w2);
  16665.            WindowWriteString(w1,"This is window 1 on page 0",1,1);
  16666.            WindowWriteString(w2,"This is window 2 on page 1",1,1);
  16667.  
  16668.            /* Display video page 0 */
  16669.            WindowDisplay(w1,1,NOEFFECT);
  16670.            GET_KEY();
  16671.  
  16672.            /* Change to video page 1 and display */
  16673.            SetVisibleVideoPage(1);
  16674.            WindowDisplay(w2,1,NOEFFECT);
  16675.            GET_KEY();
  16676.  
  16677.            /* Reset to page 0 */
  16678.            SetVisibleVideoPage(0);
  16679.          }
  16680.  
  16681.  
  16682.          The example above initializes two windows.  w1 is initialized
  16683.          on page 0 and w2 is initialized on page 1.  Also note that
  16684.  
  16685.  
  16686.  
  16687.          Page 264          The C Window Library               Page 264
  16688.  
  16689.          there are two calls to WindowSaveInitial(), one for page 0
  16690.          and another for page 1.  The first window displayed is w1.
  16691.          Once a key is pressed the visible page is switched to page 1
  16692.          by calling SetVisibleVideoPage().  The last line of the
  16693.          program sets the visible page back to page 0.  You should do
  16694.          this on exit of any program that changes video pages.
  16695.  
  16696.          If there are no errors, SetVisibleVideoPage() returns
  16697.          NO_ERROR.
  16698.  
  16699.          If there are errors, SetVisibleVideoPage() returns
  16700.          INVALID_PAGE if the video page is invalid.
  16701.  
  16702.  
  16703.  
  16704.  
  16705.  
  16706.  
  16707.  
  16708.  
  16709.  
  16710.  
  16711.  
  16712.  
  16713.  
  16714.  
  16715.  
  16716.  
  16717.  
  16718.  
  16719.  
  16720.  
  16721.  
  16722.  
  16723.  
  16724.  
  16725.  
  16726.  
  16727.  
  16728.  
  16729.  
  16730.  
  16731.  
  16732.  
  16733.  
  16734.  
  16735.  
  16736.  
  16737.  
  16738.  
  16739.  
  16740.  
  16741.  
  16742.  
  16743.  
  16744.  
  16745.  
  16746.  
  16747.          Page 265          The C Window Library               Page 265
  16748.  
  16749.                   GENERAL STRING WRITING FUNCTIONS
  16750.                   --------------------------------
  16751.  
  16752.          The following functions write strings to the active video
  16753.          page.  These functions are not window functions, therefore
  16754.          you should use these functions when you are not using windows
  16755.          created with The C Window Library unless you are careful in
  16756.          using them.  The advantage of using these functions instead
  16757.          of the normal string writing functions found in most C
  16758.          compiler libraries (i.e.  printf(), puts(), etc.) is that the
  16759.          output is written directly to screen memory, which results in
  16760.          fast output.  If the BIOS option is selected, BIOS functions
  16761.          are used to write the strings.  Refer to page 4 for a
  16762.          discussion of direct screen writing and BIOS functions.
  16763.  
  16764.  
  16765.  
  16766.  
  16767.          VideoWriteString()
  16768.          ------------------
  16769.  
  16770.          This function writes a null terminated string to the active
  16771.          video page.  Here is the prototype:
  16772.  
  16773.             void VideoWriteString(char *string, int row, int col)
  16774.  
  16775.          The first argument is the string, and the second and third
  16776.          arguments are the (row,col) position of the active video page
  16777.          to place the string.  There is no check to see if (row,col)
  16778.          is out of bounds.  The attribute that is used is determined
  16779.          by the current video attribute at each character position on
  16780.          the screen.
  16781.  
  16782.  
  16783.          Example:
  16784.  
  16785.  
  16786.          #include "window.h"
  16787.  
  16788.          main()
  16789.          {
  16790.            int i;
  16791.            WindowInitializeSystem();
  16792.            for (i=1;i<=10;i++)
  16793.              VideoWriteString("Hello, World",i,1);
  16794.          }
  16795.  
  16796.  
  16797.          There is no return value for VideoWriteString().
  16798.  
  16799.  
  16800.  
  16801.  
  16802.  
  16803.  
  16804.  
  16805.  
  16806.  
  16807.          Page 266          The C Window Library               Page 266
  16808.  
  16809.          VideoWriteStringAttr()
  16810.          ----------------------
  16811.  
  16812.          This function writes a null terminated string to the active
  16813.          video page using a video attribute.  Here is the prototype:
  16814.  
  16815.          void VideoWriteStringAttr(char *string, int row, int col,
  16816.                                    int attr)
  16817.  
  16818.          The first argument is the string, the second and third
  16819.          arguments are the (row,col) position of the active video page
  16820.          to place the string, and the last argument is the video
  16821.          attribute to use.  There is no check to see if (row,col) is
  16822.          out of bounds.  The last argument is the video attribute to
  16823.          use.
  16824.  
  16825.  
  16826.          Example:
  16827.  
  16828.  
  16829.          #include "window.h"
  16830.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  16831.  
  16832.          main()
  16833.          {
  16834.            int i;
  16835.            WindowInitializeSystem();
  16836.            for (i=1;i<=10;i++)
  16837.              VideoWriteStringAttr("Hello, World",i,1,REVERSE);
  16838.          }
  16839.  
  16840.  
  16841.          There is no return value for VideoWriteStringAttr().
  16842.  
  16843.  
  16844.  
  16845.  
  16846.  
  16847.          VideoWriteAttributes()
  16848.          ----------------------
  16849.  
  16850.          This function writes a string of attributes to the active
  16851.          video page.  Here is the prototype:
  16852.  
  16853.           void VideoWriteAttributes(char *buffer, int row, int col,
  16854.                                     int num)
  16855.  
  16856.          The first argument is the buffer that contains the video
  16857.          attributes.  The second and third arguments are the (row,col)
  16858.          position of the active video page to place the attributes,
  16859.          and the last arguments is the number of attributes to write
  16860.          from the buffer.  There is no check to see if (row,col) is
  16861.          out of bounds, or if num attributes will exceed the right
  16862.          edge of the screen.
  16863.  
  16864.  
  16865.  
  16866.  
  16867.          Page 267          The C Window Library               Page 267
  16868.  
  16869.          Example:
  16870.  
  16871.  
  16872.          #include "window.h"
  16873.          #include <string.h>
  16874.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  16875.          char buf[12];
  16876.  
  16877.          main()
  16878.          {
  16879.            WindowInitializeSystem();
  16880.            VideoWriteString("Hello, World",1,1);
  16881.            GET_KEY();
  16882.            memset(buf,REVERSE,sizeof(buf));
  16883.            VideoWriteAttributes(buf,1,1,sizeof(buf));
  16884.          }
  16885.  
  16886.          The example above writes a string using the
  16887.          VideoWriteString() function and then changes the attribute of
  16888.          the string by setting a buffer to the REVERSE attribute and
  16889.          using the VideoWriteAttributes() function with this buffer.
  16890.  
  16891.          There is no return value for VideoWriteAttributes().
  16892.  
  16893.  
  16894.  
  16895.          VideoWriteCenterString()
  16896.          ------------------------
  16897.  
  16898.          The VideoWriteCenterString() function centers a string at a
  16899.          certain row of the active video page.  Here is the prototype:
  16900.  
  16901.               void VideoWriteCenterString(char *string, int row)
  16902.  
  16903.          The first argument is the string and the second argument is
  16904.          the row to write on the active video page to write the
  16905.          string.   There is no check to see if row is out of bounds.
  16906.  
  16907.  
  16908.          Example:
  16909.  
  16910.  
  16911.          #include "window.h"
  16912.  
  16913.          main()
  16914.          {
  16915.            int i;
  16916.            WindowInitializeSystem();
  16917.            for (i=1;i<=10;i++)
  16918.              VideoWriteCenterString("Hello, World",i);
  16919.          }
  16920.  
  16921.  
  16922.          There is no return value for VideoWriteCenterString().
  16923.  
  16924.  
  16925.  
  16926.  
  16927.          Page 268          The C Window Library               Page 268
  16928.  
  16929.          VideoWriteCenterStringAttr()
  16930.          ----------------------------
  16931.  
  16932.          The VideoWriteCenterStringAttr() function centers a string at
  16933.          a certain row of the active video page with a specified video
  16934.          attribute.  Here is the prototype:
  16935.  
  16936.          void VideoWriteCenterStringAttr(char *string, int row,
  16937.                                          int attr)
  16938.  
  16939.          The first argument is the string and the second argument is
  16940.          the row to write on the active video page to write the
  16941.          string.  The third argument is the video attribute to use.
  16942.          There is no check to see if row is out of bounds.
  16943.  
  16944.  
  16945.          Example:
  16946.  
  16947.  
  16948.          #include "window.h"
  16949.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  16950.  
  16951.          main()
  16952.          {
  16953.            int i;
  16954.            WindowInitializeSystem();
  16955.            for (i=1;i<=10;i++)
  16956.              VideoWriteCenterStringAttr("Hello, World",i,REVERSE);
  16957.          }
  16958.  
  16959.          There is no return value for VideoWriteCenterStringAttr().
  16960.  
  16961.  
  16962.  
  16963.  
  16964.          VideoWriteCharAndAttr()
  16965.          -----------------------
  16966.  
  16967.          The VideoWriteCharAndAttr() function writes a string of
  16968.          character-attribute pairs to the active video page.  Here is
  16969.          the prototype:
  16970.  
  16971.          void VideoWriteCharAndAttr(char *buffer, int row, int col,
  16972.                                     int num)
  16973.  
  16974.          The first argument is the buffer that holds the character
  16975.          attribute pairs.  This buffer should be in the following
  16976.          form:
  16977.  
  16978.               -----------------------------------------------
  16979.               |char1 | attr1 | char2 | attr2 | char3 | attr3| ...
  16980.               -----------------------------------------------
  16981.  
  16982.          The second and third arguments are the (row,col) position of
  16983.          the active video page to write the string.  The last argument
  16984.  
  16985.  
  16986.  
  16987.          Page 269          The C Window Library               Page 269
  16988.  
  16989.          is the number of character-attribute pairs to write.
  16990.  
  16991.  
  16992.          Example:
  16993.  
  16994.          #include "window.h"
  16995.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  16996.          char buf[24];
  16997.  
  16998.          main()
  16999.          {
  17000.            int i,j;
  17001.            WindowInitializeSystem();
  17002.            for (i=0,j='A'; i<24; i+=2,j++)
  17003.            {
  17004.              buf[i] = j;
  17005.              buf[i+1] = REVERSE;
  17006.            }
  17007.            for (i=1;i<=10;i++)
  17008.              VideoWriteCharAndAttr(buf,i,1,12);
  17009.          }
  17010.  
  17011.          The example above creates a string of character attribute
  17012.          pairs and then writes this string using the
  17013.          VideoWriteCharAndAttr() function.
  17014.  
  17015.          There is no return value for VideoWriteCharAndAttr().
  17016.  
  17017.  
  17018.          VideoWriteStringCC()
  17019.          --------------------
  17020.  
  17021.          This function writes a string centered around a column on the
  17022.          active video page.  Here is the prototype:
  17023.  
  17024.               void VideoWriteStringCC(char *string, int row, int col)
  17025.  
  17026.          The first argument is the string.  The second argument is the
  17027.          row, and the third argument is the column to center the
  17028.          string around.
  17029.  
  17030.          Example:
  17031.  
  17032.          #include "window.h"
  17033.  
  17034.          main()
  17035.          {
  17036.            int i;
  17037.            WindowInitializeSystem();
  17038.            VideoWriteStringCC("This",1,10);
  17039.            VideoWriteStringCC("is",2,10);
  17040.            VideoWriteStringCC("centered",3,10);
  17041.            VideoWriteStringCC("around",4,10);
  17042.            VideoWriteStringCC("column",5,10);
  17043.            VideoWriteStringCC("10",6,10);
  17044.          }
  17045.  
  17046.  
  17047.          Page 270          The C Window Library               Page 270
  17048.  
  17049.          There is no return value for VideoWriteStringCC().
  17050.  
  17051.  
  17052.          VideoWriteStringCCAttr()
  17053.          ------------------------
  17054.  
  17055.          This function writes a string centered around a column on the
  17056.          active video page with a specified video attribute.  Here is
  17057.          the prototype:
  17058.  
  17059.          void VideoWriteStringCCAttr(char *string, int row, int col,
  17060.                                      int attr)
  17061.  
  17062.          The first argument is the string.  The second argument is the
  17063.          row.  The third argument is the column to center the string
  17064.          around, and the fourth argument is the attribute to use.
  17065.  
  17066.  
  17067.          Example:
  17068.  
  17069.          #include "window.h"
  17070.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  17071.          main()
  17072.          {
  17073.            int i;
  17074.            WindowInitializeSystem();
  17075.            VideoWriteStringCCAttr("This",1,10,REVERSE);
  17076.            VideoWriteStringCCAttr("is",2,10,REVERSE);
  17077.            VideoWriteStringCCAttr("centered",3,10,REVERSE);
  17078.            VideoWriteStringCCAttr("around",4,10,REVERSE);
  17079.            VideoWriteStringCCAttr("column",5,10,REVERSE);
  17080.            VideoWriteStringCCAttr("10",6,10,REVERSE);
  17081.          }
  17082.  
  17083.          There is no return value for VideoWriteStringCCAttr().
  17084.  
  17085.  
  17086.  
  17087.  
  17088.          VideoWriteStringRJ()
  17089.          --------------------
  17090.  
  17091.          The VideoWriteStringRJ() function writes a string to the
  17092.          screen that is right justified at column col.  If the string
  17093.          will not fit within column 1, the string is still right
  17094.          justified, but excess characters to the left of column 1 are
  17095.          clipped.  This function writes a string  column on the active
  17096.          video page.  Here is the prototype:
  17097.  
  17098.          void VideoWriteStringRJ(char *string, int row, int col)
  17099.  
  17100.          The first argument is the string.  The second argument is the
  17101.          row, and the third argument is the column to right justify
  17102.          the string on.
  17103.  
  17104.  
  17105.  
  17106.  
  17107.          Page 271          The C Window Library               Page 271
  17108.  
  17109.          Example:
  17110.  
  17111.          #include "window.h"
  17112.          main()
  17113.          {
  17114.            int i;
  17115.            WindowInitializeSystem();
  17116.            VideoWriteStringRJ("This",1,10);
  17117.            VideoWriteStringRJ("is",2,10);
  17118.            VideoWriteStringRJ("right",3,10);
  17119.            VideoWriteStringRJ("justified",4,10);
  17120.            VideoWriteStringRJ("on ",5,10);
  17121.            VideoWriteStringRJ("column",6,10);
  17122.            VideoWriteStringRJ("10",7,10);
  17123.          }
  17124.  
  17125.          There is no return value for VideoWriteStringRJ().
  17126.  
  17127.  
  17128.  
  17129.          VideoWriteStringRJAttr()
  17130.          ------------------------
  17131.  
  17132.          The VideoWriteStringRJAttr() function writes a string to the
  17133.          screen that is right justified at column col with a specified
  17134.          video attribute.  If the string will not fit within column 1,
  17135.          the string is still right justified, but excess characters to
  17136.          the left of column 1 are clipped.  This function writes a
  17137.          string  column on the active video page.  Here is the
  17138.          prototype:
  17139.  
  17140.          void VideoWriteStringRJAttr(char *string, int row, int col,
  17141.                                      int attr)
  17142.  
  17143.          The first argument is the string.  The second argument is the
  17144.          row.  The third argument is the column to right justify the
  17145.          string on, and the last argument is the video attribute to
  17146.          use.
  17147.  
  17148.          Example:
  17149.  
  17150.          #include "window.h"
  17151.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  17152.          main()
  17153.          {
  17154.            int i;
  17155.            WindowInitializeSystem();
  17156.            VideoWriteStringRJAttr("This",1,10,REVERSE);
  17157.            VideoWriteStringRJAttr("is",2,10,REVERSE);
  17158.            VideoWriteStringRJAttr("right",3,10,REVERSE);
  17159.            VideoWriteStringRJAttr("justified",4,10,REVERSE);
  17160.            VideoWriteStringRJAttr("on ",5,10,REVERSE);
  17161.            VideoWriteStringRJAttr("column",6,10,REVERSE);
  17162.            VideoWriteStringRJAttr("10",7,10,REVERSE);
  17163.          }
  17164.  
  17165.  
  17166.  
  17167.          Page 272          The C Window Library               Page 272
  17168.  
  17169.          There is no return value for VideoWriteStringRJAttr().
  17170.  
  17171.  
  17172.  
  17173.          VideoPrintf()
  17174.          -------------
  17175.  
  17176.          The VideoPrintf() function writes formatted strings to the
  17177.          active video page.  This function works exactly the same as
  17178.          printf() except that output is written directly to the
  17179.          screen.  Here is the prototype:
  17180.  
  17181.                 void VideoPrintf(char *format [,arg1,arg2...])
  17182.  
  17183.          The location of the output is placed at the current cursor
  17184.          position.  The cursor is advanced to one character beyond the
  17185.          last character of output.
  17186.  
  17187.          Example:
  17188.  
  17189.          #include "window.h"
  17190.          int i = 3;
  17191.          double j = 5.6;
  17192.          main()
  17193.          {
  17194.            WindowInitializeSystem();
  17195.            VideoPrintf("3+2 is equal to %d\n",3+2);
  17196.            VideoPrintf("i is equal to %d\nj is equal to %lf\n",i,j);
  17197.          }
  17198.  
  17199.          Unlike printf(), there is no return value with VideoPrintf().
  17200.  
  17201.  
  17202.  
  17203.          VideoPrintfAttr()
  17204.          -----------------
  17205.  
  17206.          The VideoPrintfAttr() function works the same as
  17207.          VideoPrintf() except that a video attribute is specified.
  17208.          Here is the prototype:
  17209.  
  17210.           void VideoPrintfAttr(int attr, char *format [,arg1,arg2...])
  17211.  
  17212.          The first argument is the attribute to use.  The second
  17213.          argument is the format string, and the other arguments are
  17214.          optional arguments.
  17215.  
  17216.  
  17217.  
  17218.  
  17219.  
  17220.  
  17221.  
  17222.  
  17223.  
  17224.  
  17225.  
  17226.  
  17227.          Page 273          The C Window Library               Page 273
  17228.  
  17229.          Example:
  17230.  
  17231.          #include "window.h"
  17232.          #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  17233.          int i = 3;
  17234.          double j = 5.6;
  17235.          main()
  17236.          {
  17237.            WindowInitializeSystem();
  17238.            VideoPrintfAttr(REVERSE,"3+2 is equal to %d\n",3+2);
  17239.            VideoPrintfAttr(REVERSE,
  17240.                   "i is equal to %d\nj is equal to %lf\n",i,j);
  17241.          }
  17242.  
  17243.          Unlike printf(), there is no return value with
  17244.          VideoPrintfAttr().
  17245.  
  17246.  
  17247.  
  17248.  
  17249.  
  17250.  
  17251.  
  17252.  
  17253.  
  17254.  
  17255.  
  17256.  
  17257.  
  17258.  
  17259.  
  17260.  
  17261.  
  17262.  
  17263.  
  17264.  
  17265.  
  17266.  
  17267.  
  17268.  
  17269.  
  17270.  
  17271.  
  17272.  
  17273.  
  17274.  
  17275.  
  17276.  
  17277.  
  17278.  
  17279.  
  17280.  
  17281.  
  17282.  
  17283.  
  17284.  
  17285.  
  17286.  
  17287.          Page 274          The C Window Library               Page 274
  17288.  
  17289.           READING CHARACTERS AND ATTRIBUTES FROM THE SCREEN
  17290.           -------------------------------------------------
  17291.  
  17292.          These functions read characters and/or attributes from the
  17293.          active video page.
  17294.  
  17295.  
  17296.          VideoReadCharacters()
  17297.          ---------------------
  17298.  
  17299.          This function reads characters from the active video page
  17300.          into a buffer.  Here is the prototype:
  17301.  
  17302.  
  17303.          void VideoReadCharacters(char *buffer, int row, int col,
  17304.                                   int num)
  17305.  
  17306.          The first argument is the buffer to store the characters.
  17307.          The second and third arguments are the (row,col) position on
  17308.          the active video page.  The last argument is the number of
  17309.          characters to read in.  There is no check to see if the row,
  17310.          col, or the num arguments are in bounds of the screen.
  17311.  
  17312.  
  17313.          Example:
  17314.  
  17315.          #include "window.h"
  17316.  
  17317.          char buf[25];
  17318.  
  17319.          main()
  17320.          {
  17321.            WindowInitializeSystem();
  17322.            VideoReadCharacters(buf,1,1,25);
  17323.          }
  17324.  
  17325.  
  17326.          The example above reads the characters on the screen starting
  17327.          at position (1,1).
  17328.  
  17329.          There is no return value for VideoReadCharacters().
  17330.  
  17331.  
  17332.  
  17333.          VideoReadAttributes()
  17334.          ---------------------
  17335.  
  17336.          This function reads attributes from the active video page
  17337.          into a buffer.  Here is the prototype:
  17338.  
  17339.          void VideoReadAttributes(char *buffer, int row, int col,
  17340.                                   int num)
  17341.  
  17342.          The first argument is the buffer to store the attributes.
  17343.          The second and third arguments are the (row,col) position on
  17344.  
  17345.  
  17346.  
  17347.          Page 275          The C Window Library               Page 275
  17348.  
  17349.          the active video page.  The last argument is the number of
  17350.          attributes to read in.  There is no check to see if the row,
  17351.          col, or the num arguments are in bounds of the screen.
  17352.  
  17353.          Example:
  17354.  
  17355.          #include "window.h"
  17356.  
  17357.          char buf[25];
  17358.  
  17359.          main()
  17360.          {
  17361.            WindowInitializeSystem();
  17362.            VideoReadAttributes(buf,1,1,25);
  17363.          }
  17364.  
  17365.          The example above reads the attributes on the screen
  17366.          starting at position (1,1).
  17367.  
  17368.          There is no return value for VideoReadAttributes().
  17369.  
  17370.  
  17371.  
  17372.          VideoReadCharAndAttr()
  17373.          ----------------------
  17374.  
  17375.          This function reads character-attribute pairs from the active
  17376.          video page into a buffer.  Here is the prototype:
  17377.  
  17378.  
  17379.          void VideoReadCharAndAttr(char *buffer, int row, int col,
  17380.                                    int num)
  17381.  
  17382.          The first argument is the buffer to store the
  17383.          character-attribute pairs.  The second and third arguments
  17384.          are the (row,col) position on the active video page.  The
  17385.          last argument is the number of character-attribute pairs to
  17386.          read in.  There is no check to see if the row, col, or the
  17387.          num arguments are in bounds of the screen.
  17388.  
  17389.          Example:
  17390.  
  17391.          #include "window.h"
  17392.  
  17393.          char buf[26];
  17394.  
  17395.          main()
  17396.          {
  17397.            WindowInitializeSystem();
  17398.            VideoReadCharAndAttr(buf,1,1,13);
  17399.          }
  17400.  
  17401.          The example above reads the character-attribute pairs on the
  17402.          screen starting at position (1,1).
  17403.  
  17404.          There is no return value for VideoReadCharAndAttr().
  17405.  
  17406.  
  17407.          Page 276          The C Window Library               Page 276
  17408.  
  17409.                             DRAWING BOXES
  17410.                             -------------
  17411.  
  17412.          The following functions draw boxes on the screen.
  17413.  
  17414.  
  17415.          VideoDrawBox()
  17416.          --------------
  17417.  
  17418.          The VideoDrawBox() function draws a box on the screen.  Here
  17419.          is the prototype:
  17420.  
  17421.          void VideoDrawBox(int urow, int ucol, int lrow, int lcol,
  17422.                            char *boxchars)
  17423.  
  17424.          The box is defined by a rectangular region.  The urow and
  17425.          ucol arguments are the coordinates of the upper left hand
  17426.          corner of the box.  The lrow and lcol arguments are the
  17427.          coordinates of the lower right hand corner of the box.  The
  17428.          last argument is a string of box drawing characters to use.
  17429.          You can use the predefined box types in the header file
  17430.          vidsys.h, or you can make your own.  Refer to page 11 for
  17431.          more information on box types.
  17432.  
  17433.          There is no check to see if the coordinates are in bounds.
  17434.  
  17435.          Example:
  17436.  
  17437.          #include "window.h"
  17438.  
  17439.          main()
  17440.          {
  17441.            WindowInitializeSystem();
  17442.            ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  17443.  
  17444.            /* Draw two boxes */
  17445.            VideoDrawBox(1,1,10,10,SINGLEBOX);
  17446.            VideoDrawBox(1,11,10,21,DOUBLEBOX);
  17447.          }
  17448.  
  17449.          There is no return value for VideoDrawBox().
  17450.  
  17451.  
  17452.  
  17453.          VideoDrawBoxAttr()
  17454.          ------------------
  17455.  
  17456.          The VideoDrawBoxAttr() function draws a box on the screen
  17457.          with a specified video attribute.  Here is the prototype:
  17458.  
  17459.          void VideoDrawBoxAttr(int urow, int ucol, int lrow, int lcol,
  17460.                                char *boxchars, int attr)
  17461.  
  17462.          This function works the same way as the VideoDrawBox()
  17463.          function.  Note that the last argument is the video attribute
  17464.  
  17465.  
  17466.  
  17467.          Page 277          The C Window Library               Page 277
  17468.  
  17469.          to use.  There is no check to see if the coordinates are in
  17470.          bounds.
  17471.  
  17472.  
  17473.          Example:
  17474.  
  17475.          #include "window.h"
  17476.          #define REVERSE CREATE_VIDEO_ATTRIBUTE(black,white)
  17477.  
  17478.          main()
  17479.          {
  17480.            WindowInitializeSystem();
  17481.            ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  17482.  
  17483.            /* Draw two boxes */
  17484.            VideoDrawBoxAttr(1,1,10,10,SINGLEBOX,REVERSE);
  17485.            VideoDrawBoxAttr(1,11,10,21,DOUBLEBOX,REVERSE);
  17486.          }
  17487.  
  17488.  
  17489.          There is no return value for VideoDrawBoxAttr().
  17490.  
  17491.  
  17492.  
  17493.  
  17494.  
  17495.  
  17496.  
  17497.  
  17498.  
  17499.  
  17500.  
  17501.  
  17502.  
  17503.  
  17504.  
  17505.  
  17506.  
  17507.  
  17508.  
  17509.  
  17510.  
  17511.  
  17512.  
  17513.  
  17514.  
  17515.  
  17516.  
  17517.  
  17518.  
  17519.  
  17520.  
  17521.  
  17522.  
  17523.  
  17524.  
  17525.  
  17526.  
  17527.          Page 278          The C Window Library               Page 278
  17528.  
  17529.                  SAVING AND RESTORING SCREEN IMAGES
  17530.                  ----------------------------------
  17531.  
  17532.          The following functions save rectangular regions of the
  17533.          screen in a buffer, and restore rectangular portions of the
  17534.          screen.  These routines exist in The C Window Library so that
  17535.          advanced C programmers can have general screen
  17536.          saving/restoring routines handy.  As always, you should be
  17537.          careful in using these functions at the same time you are
  17538.          using windows created with The C Window Library.
  17539.  
  17540.  
  17541.          VideoSave()
  17542.          -----------
  17543.  
  17544.          The VideoSave() function saves a rectangular portion of the
  17545.          screen into a structure called a VBLOCK.  A pointer to this
  17546.          structure is called a VBLOCKPTR.  Here is the prototype:
  17547.  
  17548.          VBLOCKPTR VideoSave(int urow, int ucol, int lrow, int lcol)
  17549.  
  17550.          This function returns a VBLOCKPTR.  The VBLOCKPTR will be
  17551.          used to move or restore this saved region.  The first two
  17552.          arguments are the coordinates of the upper left hand corner
  17553.          of the rectangle to save (urow,ucol).  The last two arguments
  17554.          are the coordinates of the lower right hand corner of the
  17555.          rectangle (lrow,lcol).  There is no check to see if the
  17556.          coordinates are out of bounds.  You can use this function to
  17557.          save the base screen, and then use VideoRestore() to restore
  17558.          the base screen on exit.
  17559.  
  17560.          Example:
  17561.  
  17562.          #include "window.h"
  17563.  
  17564.          VBLOCKPTR v;
  17565.  
  17566.          main()
  17567.          {
  17568.            WindowInitializeSystem();
  17569.            v = VideoSave(1,1,25,80);   /* Save Rectangular region */
  17570.  
  17571.            /* Check if NULL */
  17572.            if (v == (VBLOCKPTR)0)
  17573.              VideoWriteString("Trouble saving video");
  17574.          }
  17575.  
  17576.          If there are no errors, VideoSave() returns a valid VBLOCKPTR.
  17577.  
  17578.          If there are errors VideoSave() returns a null VBLOCKPTR and
  17579.          sets the global integer window_error_code to the following
  17580.          value:
  17581.  
  17582.          NO_HEAP_MEM if there is not enough memory for the save buffer
  17583.          of the VBLOCKPTR.
  17584.  
  17585.  
  17586.  
  17587.          Page 279          The C Window Library               Page 279
  17588.  
  17589.          VideoMove()
  17590.          -----------
  17591.  
  17592.          The VideoMove() function moves a region saved by VideoSave()
  17593.          to a different location of the screen.  This location will be
  17594.          the new upper left hand corner of the rectangular region that
  17595.          was saved.  The move is not displayed until you call
  17596.          VideoRestore(), which is defined later.   Here is the
  17597.          prototype:
  17598.  
  17599.               void VideoMove(VBLOCKPTR v, int row, int col)
  17600.  
  17601.          The first argument is the VBLOCKPTR.  The second and third
  17602.          arguments are the new upper left hand position of the saved
  17603.          area.  There is NO check to see if the VBLOCKPTR exists, or
  17604.          the row or column are valid.
  17605.  
  17606.          Example:
  17607.  
  17608.          #include "window.h"
  17609.  
  17610.          VBLOCKPTR v;
  17611.  
  17612.          main()
  17613.          {
  17614.            WindowInitializeSystem();
  17615.            v = VideoSave(1,1,10,10);   /* Save Rectangular region
  17616.                                           defined by (1,1) (10,10) */
  17617.            VideoMove(v,1,10);
  17618.          }
  17619.  
  17620.          There is no return value for VideoMove().
  17621.  
  17622.  
  17623.  
  17624.  
  17625.          VideoRestore()
  17626.          --------------
  17627.  
  17628.          The VideoRestore() function takes a rectangular area of the
  17629.          screen saved with VideoSave() and redisplays the area.  Here
  17630.          is the prototype:
  17631.  
  17632.                         void VideoRestore(VBLOCKPTR v)
  17633.  
  17634.          The only argument is the VBLOCKPTR.  There is no check to see
  17635.          if the VBLOCKPTR is valid.
  17636.  
  17637.  
  17638.          Example:
  17639.  
  17640.  
  17641.          #include "window.h"
  17642.  
  17643.          VBLOCKPTR v;
  17644.  
  17645.  
  17646.  
  17647.          Page 280          The C Window Library               Page 280
  17648.  
  17649.          main()
  17650.          {
  17651.            WindowInitializeSystem();
  17652.            v = VideoSave(1,1,10,10);
  17653.            for (i=1;i<=10;i++)
  17654.              VideoWriteString("This is the save area. "
  17655.                               "Press a key to restore.",i,1);
  17656.            GET_KEY();
  17657.            VideoRestore(v);
  17658.          }
  17659.  
  17660.  
  17661.          There is no return value for VideoRestore().
  17662.  
  17663.  
  17664.  
  17665.  
  17666.          VideoFree()
  17667.          -----------
  17668.  
  17669.          The VideoFree() function frees a previously defined
  17670.          VBLOCKPTR.  Here is the prototype:
  17671.  
  17672.                   void VideoFree(VBLOCKPTR v)
  17673.  
  17674.          The only argument is the VBLOCKPTR.  There is NO check to see
  17675.          if the VBLOCKPTR is valid,  therefore you must be very
  17676.          careful to call this function on a valid VBLOCKPTR.  If not,
  17677.          the heap will become corrupted.
  17678.  
  17679.          Example:
  17680.  
  17681.          #include "window.h"
  17682.  
  17683.          VBLOCKPTR v;
  17684.  
  17685.          main()
  17686.          {
  17687.            WindowInitializeSystem();
  17688.            v = VideoSave(1,1,10,10);
  17689.            for (i=1;i<=10;i++)
  17690.              VideoWriteString("This is the save area. "
  17691.                               "Press a key to restore.",i,1);
  17692.            GET_KEY();
  17693.            VideoRestore(v);
  17694.            VideoFree(v);
  17695.          }
  17696.  
  17697.          There is no return value for VideoFree().
  17698.  
  17699.  
  17700.  
  17701.  
  17702.  
  17703.  
  17704.  
  17705.  
  17706.  
  17707.          Page 281          The C Window Library               Page 281
  17708.  
  17709.                           CLEARING SCREENS
  17710.                           ----------------
  17711.  
  17712.          The following functions clears the visible video page, and
  17713.          clears regions of the visible screen.
  17714.  
  17715.  
  17716.  
  17717.          ClearScreen()
  17718.          -------------
  17719.  
  17720.          The ClearScreen() function clears the visible video page with
  17721.          a specified attribute and moves the screen cursor to position
  17722.          (1,1).  Here is the prototype:
  17723.  
  17724.                        void ClearScreen(int attr)
  17725.  
  17726.          The only argument is the video attribute to use.
  17727.  
  17728.          Example:
  17729.  
  17730.  
  17731.          #include "window.h"
  17732.  
  17733.          main()
  17734.          {
  17735.            WindowInitializeSystem();
  17736.  
  17737.            /* Clear the entire screen */
  17738.            ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  17739.          }
  17740.  
  17741.          There is no return value for ClearScreen().
  17742.  
  17743.  
  17744.  
  17745.  
  17746.  
  17747.          ClearRegion()
  17748.          -------------
  17749.  
  17750.          This function clears a rectangular region of the screen.
  17751.          Here is the prototype:
  17752.  
  17753.          void ClearRegion(int urow, int ucol, int lrow, int lcol,
  17754.                           int attr)
  17755.  
  17756.          The first two arguments represent the coordinate of the upper
  17757.          left hand coordinates of the rectangular region to clear.
  17758.          The third and fourth arguments represent the coordinate of
  17759.          the lower right hand corner of the rectangular region.  The
  17760.          last argument is the attribute to use.  There is no check to
  17761.          see if the coordinates are in bounds.
  17762.  
  17763.  
  17764.  
  17765.  
  17766.  
  17767.          Page 282          The C Window Library               Page 282
  17768.  
  17769.          Example:
  17770.  
  17771.          #include "window.h"
  17772.  
  17773.          main()
  17774.          {
  17775.            WindowInitializeSystem();
  17776.  
  17777.          /* Clear Region defined by (1,1) as the upper right hand
  17778.               corner and (10,10) as the lower right hand corner */
  17779.  
  17780.            ClearRegion(1,1,10,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  17781.          }
  17782.  
  17783.  
  17784.          There is no return value for ClearRegion().
  17785.  
  17786.  
  17787.  
  17788.  
  17789.  
  17790.  
  17791.  
  17792.  
  17793.  
  17794.  
  17795.  
  17796.  
  17797.  
  17798.  
  17799.  
  17800.  
  17801.  
  17802.  
  17803.  
  17804.  
  17805.  
  17806.  
  17807.  
  17808.  
  17809.  
  17810.  
  17811.  
  17812.  
  17813.  
  17814.  
  17815.  
  17816.  
  17817.  
  17818.  
  17819.  
  17820.  
  17821.  
  17822.  
  17823.  
  17824.  
  17825.  
  17826.  
  17827.          Page 283          The C Window Library               Page 283
  17828.  
  17829.                           SCROLLING SCREENS
  17830.                           -----------------
  17831.  
  17832.          These functions scroll portions of the screen up or down.
  17833.  
  17834.  
  17835.  
  17836.          ScrollScreenUp()
  17837.          ----------------
  17838.  
  17839.          The ScrollScreenUp() function scrolls a rectangular portion
  17840.          of the screen up a specified number of lines.  Here is the
  17841.          prototype:
  17842.  
  17843.          void ScrollScreenUp(int numlines, int urow, int ucol,
  17844.                              int lrow, int lcol, int attr)
  17845.  
  17846.          The first argument is the number of lines to scroll the
  17847.          region.  The second and third arguments are the (row,col)
  17848.          coordinates of the upper left hand corner of the rectangular
  17849.          region to scroll.  The fourth and fifth arguments are the
  17850.          (row,col) of the lower right hand corner of the rectangular
  17851.          region.  The last argument is the attribute to use for blank
  17852.          lines created when the region is scrolled.
  17853.  
  17854.  
  17855.          Example:
  17856.  
  17857.          #include "window.h"
  17858.  
  17859.          main()
  17860.          {
  17861.            WindowInitializeSystem();
  17862.            ScrollScreenUp(1,1,3,5,10,
  17863.                           CREATE_VIDEO_ATTRIBUTE(black,white));
  17864.          }
  17865.  
  17866.          There is no return value for ScrollScreenUp().
  17867.  
  17868.  
  17869.  
  17870.          ScrollScreenDown()
  17871.          ------------------
  17872.  
  17873.          The ScrollScreenDown() function scrolls a rectangular portion
  17874.          of the screen down a specified number of lines.  Here is the
  17875.          prototype:
  17876.  
  17877.          void ScrollScreenDown(int numlines, int urow, int ucol,
  17878.                                int lrow, int lcol, int attr)
  17879.  
  17880.          The first argument is the number of lines to scroll the
  17881.          region.  The second and third arguments are the (row,col)
  17882.          coordinates of the upper left hand corner of the rectangular
  17883.          region to scroll.  The fourth and fifth arguments are the
  17884.  
  17885.  
  17886.  
  17887.          Page 284          The C Window Library               Page 284
  17888.  
  17889.          (row,col) of the lower right hand corner of the rectangular
  17890.          region.  The last argument is the attribute to use for blank
  17891.          lines created when the region is scrolled.
  17892.  
  17893.          Example:
  17894.  
  17895.          #include "window.h"
  17896.  
  17897.          main()
  17898.          {
  17899.            WindowInitializeSystem();
  17900.            ScrollScreenDown(1,1,3,5,10,
  17901.                             CREATE_VIDEO_ATTRIBUTE(black,white));
  17902.          }
  17903.  
  17904.          There is no return value for ScrollScreenDown().
  17905.  
  17906.  
  17907.  
  17908.  
  17909.  
  17910.  
  17911.  
  17912.  
  17913.  
  17914.  
  17915.  
  17916.  
  17917.  
  17918.  
  17919.  
  17920.  
  17921.  
  17922.  
  17923.  
  17924.  
  17925.  
  17926.  
  17927.  
  17928.  
  17929.  
  17930.  
  17931.  
  17932.  
  17933.  
  17934.  
  17935.  
  17936.  
  17937.  
  17938.  
  17939.  
  17940.  
  17941.  
  17942.  
  17943.  
  17944.  
  17945.  
  17946.  
  17947.          Page 285          The C Window Library               Page 285
  17948.  
  17949.                        CHANGING THE VIDEO MODE
  17950.                        -----------------------
  17951.  
  17952.          With The C Window Library, you can change the video mode at
  17953.          any time.  The video mode determines the width of the screen,
  17954.          and whether the screen is in text or graphics mode.
  17955.  
  17956.  
  17957.          SetVideoMode()
  17958.          --------------
  17959.  
  17960.          The SetVideoMode() function changes the video mode.  Here is
  17961.          a prototype:
  17962.  
  17963.                  void SetVideoMode(int modenum)
  17964.  
  17965.          The only argument is the mode number.  Refer to the Video
  17966.          Paging section on page 5 for more information on mode numbers
  17967.          and what they display.
  17968.  
  17969.          When the video mode is changed, the screen is cleared.  This
  17970.          cannot be prevented.  You must redisplay any windows that
  17971.          were on the screen.  If the change of video mode results in a
  17972.          change in screen dimensions, then you must read the following
  17973.          sections on CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE
  17974.          SCREEN.  Even though The C Window Library does not support
  17975.          graphics mode, you can change to graphics mode in The C
  17976.          Window Library,
  17977.  
  17978.          Example:
  17979.  
  17980.          #include "window.h"
  17981.  
  17982.          main()
  17983.          {
  17984.            WindowInitializeSystem();
  17985.            SetVideoMode(3);          /* Change to video mode 3 */
  17986.          }
  17987.  
  17988.          There is no return value for SetVideoMode().
  17989.  
  17990.  
  17991.  
  17992.  
  17993.  
  17994.  
  17995.  
  17996.  
  17997.  
  17998.  
  17999.  
  18000.  
  18001.  
  18002.  
  18003.  
  18004.  
  18005.  
  18006.  
  18007.          Page 286          The C Window Library               Page 286
  18008.  
  18009.          CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE SCREEN
  18010.          -----------------------------------------------------
  18011.  
  18012.  
  18013.          Changing rows
  18014.          -------------
  18015.  
  18016.          With The C Window Library, you can change the number of rows
  18017.          on the video screen.  However, there are some things to watch
  18018.          out for when changing the number of rows, especially if you
  18019.          have windows displayed on the screen.  If you are not using
  18020.          any window related functions, you can change the number of
  18021.          displayable rows safely by doing two things:
  18022.  
  18023.          a) Call the SetVideoRows() function to change the number of
  18024.             rows.
  18025.  
  18026.          b) Call AdjustGlobalData() to adjust the global variables
  18027.             used by The C Window Library that keep track of the screen
  18028.             dimensions.
  18029.  
  18030.  
  18031.          If you are going to create or have created windows you must
  18032.          do three things:
  18033.  
  18034.          a)  Make sure that any window defined will have valid
  18035.              coordinates when the number of rows are changed.  There
  18036.              may be cases where a window occupies a row that exists in
  18037.              one screen mode, but the row does not exist in another
  18038.              screen mode.  If there are windows that will have invalid
  18039.              coordinates in another screen configuration, you must
  18040.              resize them, remove them, or whatever it takes to resolve
  18041.              the invalid coordinates.
  18042.  
  18043.          b)  Call the SetVideoRows() function.
  18044.  
  18045.          c)  Call the AdjustScreenInfo() function.  This function
  18046.              adjusts all global variables defined in The C Window
  18047.              Library to reflect the new number of rows.
  18048.  
  18049.          Whether there are or are not windows defined, the visible
  18050.          video page MUST be page 0 before changing the number of
  18051.          screen rows.
  18052.  
  18053.  
  18054.  
  18055.          AdjustScreenInfo()
  18056.          ------------------
  18057.  
  18058.          This function must be called after SetVideoRows() is called
  18059.          if you are going to, or have initialized and/or displayed
  18060.          windows.  Here is the prototype:
  18061.  
  18062.                      int AdjustScreenInfo(int page)
  18063.  
  18064.  
  18065.  
  18066.  
  18067.          Page 287          The C Window Library               Page 287
  18068.  
  18069.          The only argument is the video page to adjust to the new
  18070.          screen height.  Because of the new dimension of the screen,
  18071.          there has to be a reshuffling of a few global arrays,
  18072.          constants, variables, etc.  The AdjustScreenInfo() function
  18073.          does just this.  If you do not call AdjustScreenInfo(), you
  18074.          may see problems if you try to manipulate windows on the new
  18075.          screen.
  18076.  
  18077.          See SetVideoRows() for an example of AdjustScreenInfo().
  18078.  
  18079.          If there are no errors, AdjustScreenInfo() returns NO_ERROR.
  18080.  
  18081.          If there are errors, AdjustScreenInfo() returns the following
  18082.          value:
  18083.  
  18084.          NO_HEAP_MEM if there is not enough memory to allocate for the
  18085.          global arrays, structures, etc.
  18086.  
  18087.  
  18088.  
  18089.  
  18090.          AdjustGlobalData()
  18091.          ------------------
  18092.  
  18093.          The AdjustGlobalData() function should be called after you
  18094.          have changed the number of video rows using SetVideoRows()
  18095.          (defined below).  This resets the global variables necessary
  18096.          for non-window functions to execute properly.  Here is the
  18097.          prototype:
  18098.  
  18099.                       void AdjustGlobalData(void)
  18100.  
  18101.          There are no arguments and no return value for
  18102.          AdjustGlobalData().  If you have called AdjustScreenInfo(),
  18103.          you do not have to call AdjustGlobalData().
  18104.  
  18105.          See below for an example of AdjustGlobalData().
  18106.  
  18107.  
  18108.  
  18109.  
  18110.  
  18111.          SetVideoRows()
  18112.          --------------
  18113.  
  18114.          The SetVideoRows() function changes the number of video rows
  18115.          on the screen.  Here is a list of video adapters and there
  18116.          row number capabilities:
  18117.  
  18118.  
  18119.  
  18120.  
  18121.  
  18122.  
  18123.  
  18124.  
  18125.  
  18126.  
  18127.          Page 288          The C Window Library               Page 288
  18128.  
  18129.              Video Type                 Number of Rows
  18130.                                            Possible
  18131.              ----------                 --------------
  18132.              CGA, MDA, Hercules              25
  18133.  
  18134.              EGA                            25, 43
  18135.  
  18136.              MCGA                           25, 50
  18137.  
  18138.              VGA                            12, 14, 21, 25, 28, 43, 50
  18139.  
  18140.          The list above are the values SetVideoRows() uses, depending
  18141.          on the adapter that The C Window Library has detected.  If
  18142.          your video card supports a row configuration that is not
  18143.          supported by the SetVideoRows() function,  consult the
  18144.          'Changing columns' section and proceed as if you are changing
  18145.          the number of columns.
  18146.  
  18147.          Here is the prototype for SetVideoRows():
  18148.  
  18149.                 int SetVideoRows(int numrows, int modeflag)
  18150.  
  18151.          The first argument is the number of screen rows.  The
  18152.          modeflag tells whether the video mode should be reset.  If
  18153.          modeflag is 0, the video mode is not reset.  Any other value
  18154.          for modeflag will cause a video mode reset.  This reset may
  18155.          or may not be necessary, so experiment with both values for
  18156.          modeflag.
  18157.  
  18158.          Example:
  18159.  
  18160.          #include "window.h"
  18161.  
  18162.          main()
  18163.          {
  18164.            WindowInitializeSystem();
  18165.            ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  18166.            VideoWriteString(
  18167.                     "Press a key to change to a new video mode",1,1);
  18168.            GET_KEY();
  18169.            if (VGA_MODE_ON || MCGA_MODE_ON)
  18170.              SetVideoRows(50,0);
  18171.            else
  18172.            if (EGA_MODE_ON)
  18173.              SetVideoRows(43,0);
  18174.            else
  18175.            {
  18176.              VideoWriteString(
  18177.               "Hardware does not support changing video rows",2,1);
  18178.              exit(0);
  18179.            }
  18180.  
  18181.            AdjustGlobalData();
  18182.            VideoWriteString(
  18183.                   "Press a key again to change to 25 lines",2,1);
  18184.  
  18185.  
  18186.  
  18187.          Page 289          The C Window Library               Page 289
  18188.  
  18189.            GET_KEY();
  18190.            SetVideoRows(25,0);
  18191.            AdjustGlobalData();
  18192.          }
  18193.  
  18194.  
  18195.          The example above uses the constants VGA_MODE_ON,
  18196.          MCGA_MODE_ON, and EGA_MODE_ON.  These constants are discussed
  18197.          in the VIDEO MACROS section.
  18198.  
  18199.  
  18200.          Here is another example, but now we have a window on the
  18201.          screen.
  18202.  
  18203.  
  18204.          Example:
  18205.  
  18206.          #include "window.h"
  18207.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  18208.  
  18209.          WPOINTER w;
  18210.  
  18211.          main()
  18212.          {
  18213.            WindowInitializeSystem();
  18214.            WindowSaveInitial(0);
  18215.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  18216.            WindowOpen(w);
  18217.            WindowDisplay(w,1,NOEFFECT);
  18218.            WindowWriteString(w,"Press a key to change rows",1,1);
  18219.            GET_KEY();
  18220.            if (VGA_MODE_ON || MCGA_MODE_ON)
  18221.              SetVideoRows(50,0);
  18222.            else
  18223.            if (EGA_MODE_ON)
  18224.              SetVideoRows(43,0);
  18225.            else
  18226.            {
  18227.              WindowWriteString(w,"Cannot change rows",1,1);
  18228.              exit(0);
  18229.            }
  18230.  
  18231.            /* Adjust the screen information */
  18232.            AdjustScreenInfo(0);
  18233.  
  18234.            /* OK to adjust to new height */
  18235.            WindowResizeHeight(w,40,ANCHORTOP);
  18236.  
  18237.            WindowWriteString(w,"Now press a key to change back",2,1);
  18238.            GET_KEY();
  18239.  
  18240.            /*  First we must resize window */
  18241.            WindowResizeHeight(w,10,ANCHORTOP);
  18242.  
  18243.            SetVideoRows(25,0);
  18244.  
  18245.  
  18246.  
  18247.          Page 290          The C Window Library               Page 290
  18248.  
  18249.            AdjustScreenInfo(0);
  18250.  
  18251.          }
  18252.  
  18253.          Note the use of AdjustScreenInfo() after a reset is made.
  18254.  
  18255.          If there are no errors, SetVideoRows() returns no errors.
  18256.  
  18257.          If there are errors SetVideoRows() returns the following
  18258.          value:
  18259.  
  18260.          INVALID_ROWS if the number of rows is not supported for the
  18261.          detected monitor type.
  18262.  
  18263.  
  18264.  
  18265.          Changing columns
  18266.          ----------------
  18267.  
  18268.          The number of columns can be changed, but there are two
  18269.          things to watch out for.  First, to change from 40 column
  18270.          mode to 80 column mode or vice-versa, is a matter of changing
  18271.          the video mode.  Changing the video mode from 40 to 80 column
  18272.          mode or from 80 to 40 requires a BIOS function that is
  18273.          present on all systems that support 40 column mode.
  18274.  
  18275.  
  18276.  
  18277.          40 column and 80 column modes
  18278.          -----------------------------
  18279.  
  18280.          To change to 40 column mode do the following:
  18281.  
  18282.          SetVideoMode(0);   /* this changes to 40 column
  18283.                                black and white mode */
  18284.  
  18285.               or
  18286.  
  18287.          SetVideoMode(1);   /* this changes to 40 column color mode */
  18288.  
  18289.          The example above only works if you have a CGA, EGA, MCGA, or
  18290.          VGA card.
  18291.  
  18292.  
  18293.  
  18294.          To change to 80 column mode do the following:
  18295.  
  18296.          SetVideoMode(2);  /* this changes to Black and White
  18297.                               80 column mode */
  18298.  
  18299.               or
  18300.  
  18301.          SetVideoMode(3);  /* use this for color 80 column mode */
  18302.  
  18303.               or
  18304.  
  18305.  
  18306.  
  18307.          Page 291          The C Window Library               Page 291
  18308.  
  18309.          SetVideoMode(7);  /* use this for mono cards */
  18310.  
  18311.          SetVideoMode(7) works for all adapters, while SetVideoMode(2)
  18312.          and SetVideoMode(3) works only for CGA, EGA, MCGA, or VGA
  18313.          cards.
  18314.  
  18315.  
  18316.          Modes higher than 80 columns
  18317.          ----------------------------
  18318.  
  18319.          There are video systems that support video modes greater than
  18320.          80 columns.  The problem is that for each different brand of
  18321.          video adapter, there is a unique way of changing to a higher
  18322.          column mode.  Most of these adapters support an additional
  18323.          BIOS function that must be called to change to any screen
  18324.          column mode higher than 80.  Therefore, it is up to you (the
  18325.          programmer) to find out how to change the video system from
  18326.          80 columns to a higher column mode.  Once you are familiar
  18327.          with how to do this, changing the number of columns is almost
  18328.          the same as changing the number of rows.
  18329.  
  18330.          If you are using any window related functions, you can change
  18331.          the number of displayable columns safely by doing three
  18332.          things:
  18333.  
  18334.          a) Call the appropriate routine to change the number of
  18335.             columns.  If this is a call to SetVideoMode(), the screen
  18336.             will be cleared.
  18337.  
  18338.          b) Call AdjustScreenInfo() to adjust the global variables
  18339.             used by The C Window Library that keep track of the screen
  18340.             dimensions.
  18341.  
  18342.          c) Readjust and/or redraw any windows on the screen.  Make
  18343.             sure that all windows fit on the screen, whether they are
  18344.             hidden or not.
  18345.  
  18346.          If you are not using any windows in your application, replace
  18347.          the call to AdjustScreenInfo() in step b) with a call to
  18348.          AdjustGlobalData().
  18349.  
  18350.          This example works for the ATI VGA card.  This changes the
  18351.          mode to 132 columns:
  18352.  
  18353.          #include "window.h"
  18354.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  18355.  
  18356.          WPOINTER w;
  18357.  
  18358.          main()
  18359.          {
  18360.            WindowInitializeSystem();
  18361.            WindowSaveInitial(0);
  18362.            w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  18363.            WindowOpen(w);
  18364.  
  18365.  
  18366.  
  18367.          Page 292          The C Window Library               Page 292
  18368.  
  18369.            WindowDisplay(w,1,NOEFFECT);
  18370.            WindowWriteString(w,"Press a key to change columns",1,1);
  18371.            GET_KEY();
  18372.  
  18373.            /* Set Video Mode to 132 columns x 25 rows
  18374.               (Works for ATI VGA card) */
  18375.            SetVideoMode(0x23);
  18376.            /* Adjust the screen information and redisplay window */
  18377.            AdjustScreenInfo(0);
  18378.            WindowDisplay(w,1,NOEFFECT);
  18379.  
  18380.            /* OK to adjust to new height */
  18381.            WindowResizeWidth(w,100,ANCHORLEFT);
  18382.  
  18383.            WindowWriteString(w,"Now press a key to change back",2,1);
  18384.            GET_KEY();
  18385.  
  18386.            /*  First we must resize window */
  18387.            WindowResizeWidth(w,30,ANCHORLEFT);
  18388.  
  18389.            /* Set back to 80 column mode */
  18390.            SetVideoMode(3);
  18391.            AdjustScreenInfo(0);
  18392.            WindowDisplay(w,1,NOEFFECT);
  18393.          }
  18394.  
  18395.  
  18396.  
  18397.  
  18398.  
  18399.  
  18400.  
  18401.  
  18402.  
  18403.  
  18404.  
  18405.  
  18406.  
  18407.  
  18408.  
  18409.  
  18410.  
  18411.  
  18412.  
  18413.  
  18414.  
  18415.  
  18416.  
  18417.  
  18418.  
  18419.  
  18420.  
  18421.  
  18422.  
  18423.  
  18424.  
  18425.  
  18426.  
  18427.          Page 293          The C Window Library               Page 293
  18428.  
  18429.                          CURSOR MANIPULATION
  18430.                          -------------------
  18431.  
  18432.          The functions defined in this section manipulate the cursor.
  18433.          The following functions can be called without calling
  18434.          WindowInitializeSystem().
  18435.  
  18436.  
  18437.  
  18438.  
  18439.          MoveCursor()
  18440.          ------------
  18441.  
  18442.          This function moves the cursor to a different location.  Here
  18443.          is the prototype:
  18444.  
  18445.                 void MoveCursor(int row, int col, int page)
  18446.  
  18447.          The first two arguments are the row and column positions of
  18448.          where to move the cursor.  The last argument is the video
  18449.          page of the cursor you want to move.
  18450.  
  18451.  
  18452.          Example:
  18453.  
  18454.          #include "window.h"
  18455.  
  18456.          main()
  18457.          {
  18458.            MoveCursor(1,5,0);    /* Move cursor to row 1 column 5
  18459.                                     on video page 0 */
  18460.          }
  18461.  
  18462.          There is no return value for MoveCursor().
  18463.  
  18464.  
  18465.  
  18466.  
  18467.  
  18468.          ChangeCursor()
  18469.          --------------
  18470.  
  18471.          The ChangeCursor() function changes the shape of the cursor.
  18472.          The shape of the cursor is determined by its starting and
  18473.          ending scan lines.  Here is a prototype:
  18474.  
  18475.            void ChangeCursor(unsigned startline, unsigned endline)
  18476.  
  18477.          The first argument is the starting scan line and the second
  18478.          argument is the ending scan line.  For monochrome systems,
  18479.          there are 12 scan lines numbered 0 thru 11, while on color
  18480.          systems there are 8 scan lines numbered 0 thru 7.  The
  18481.          starting scan line is the top line of the cursor, and the
  18482.          ending scan line is the last line of the cursor.  There is no
  18483.          check to see if the starting scan line and the ending scan
  18484.          lines are valid.
  18485.  
  18486.  
  18487.          Page 294          The C Window Library               Page 294
  18488.  
  18489.          Example:
  18490.  
  18491.          #include "window.h"
  18492.  
  18493.          main()
  18494.          {
  18495.            WindowInitializeSystem();
  18496.            ChangeCursor(6,7);  /* This is an underline cursor */
  18497.            GET_KEY();
  18498.            ChangeCursor(0,7);  /* This is a thick cursor */
  18499.          }
  18500.  
  18501.          There is no return for ChangeCursor().
  18502.  
  18503.  
  18504.  
  18505.  
  18506.          GetCursorShape()
  18507.          ----------------
  18508.  
  18509.          This function returns the shape of the cursor in scan lines.
  18510.          Here is the prototype:
  18511.  
  18512.            void GetCursorShape(unsigned *startline, unsigned *endline)
  18513.  
  18514.          When this function returns, the staring scan line is placed
  18515.          in the integer pointed to by scanline, and the ending scan
  18516.          line is placed in the integer pointed to by endline.
  18517.  
  18518.          Example:
  18519.  
  18520.          #include "window.h"
  18521.  
  18522.          main()
  18523.          {
  18524.            int start, end;
  18525.            WindowInitializeSystem();
  18526.            GetCursorShape(&start, &end);
  18527.            VideoPrintf("\nThe starting scan line is %d\n"
  18528.                        "The ending scan line is %d", start,end);
  18529.          }
  18530.  
  18531.          There is no return value for GetCursorShape().
  18532.  
  18533.  
  18534.  
  18535.          GetCursorPosition()
  18536.          -------------------
  18537.  
  18538.          This function gets the current cursor position.  Here is the
  18539.          prototype:
  18540.  
  18541.             void GetCursorPosition(int *row, int *col, int page)
  18542.  
  18543.          The first argument is a pointer to an integer that will be
  18544.  
  18545.  
  18546.  
  18547.          Page 295          The C Window Library               Page 295
  18548.  
  18549.          set to the current row.  The second argument is a pointer to
  18550.          an integer that will be set to the current column.  The last
  18551.          argument is the video page of the cursor.
  18552.  
  18553.          Example:
  18554.  
  18555.  
  18556.          #include "window.h"
  18557.  
  18558.          main()
  18559.          {
  18560.            int row,col;
  18561.            MoveCursor(10,15);
  18562.            GetCursorPosition(&row,&col,0);
  18563.            WindowInitializeSystem();
  18564.            VideoPrintf("\nThe row of the cursor is %d\n"
  18565.                        "The column is %d", row,col);
  18566.          }
  18567.  
  18568.  
  18569.          There is no return value for GetCursorPosition().
  18570.  
  18571.  
  18572.  
  18573.          The following functions serve as shortcuts in changing the
  18574.          cursor shape.
  18575.  
  18576.  
  18577.          HideCursor()
  18578.          ------------
  18579.  
  18580.          Hides the cursor on the screen.  Here is the prototype:
  18581.  
  18582.                       void HideCursor(void)
  18583.  
  18584.  
  18585.          BlockCursor()
  18586.          -------------
  18587.  
  18588.          Displays the cursor as a thick block.
  18589.  
  18590.                       void BlockCursor(void)
  18591.  
  18592.          ThinCursor()
  18593.          ------------
  18594.  
  18595.          Displays the cursor as an underline cursor.
  18596.  
  18597.                       void ThinCursor(void)
  18598.  
  18599.  
  18600.  
  18601.  
  18602.  
  18603.  
  18604.  
  18605.  
  18606.  
  18607.          Page 296          The C Window Library               Page 296
  18608.  
  18609.          Example:
  18610.  
  18611.          #include "window.h"
  18612.  
  18613.          main()
  18614.          {
  18615.            WindowInitializeSystem();
  18616.            MoveCursor(1,1,0);
  18617.            VideoWriterString("Press a key to hide the cursor",1,1);
  18618.            GET_KEY();
  18619.            HideCursor();
  18620.            VideoWriterString(
  18621.                    "Press a key to change cursor to a block",2,1);
  18622.            GET_KEY();
  18623.            BlockCursor();
  18624.            VideoWriterString(
  18625.               "Press a key to change cursor to a thin cursor",3,1);
  18626.            GET_KEY();
  18627.            ThinCursor();
  18628.          }
  18629.  
  18630.  
  18631.          There are no return values for HideCursor(), BlockCursor(),
  18632.          or ThinCursor().
  18633.  
  18634.  
  18635.  
  18636.  
  18637.  
  18638.  
  18639.  
  18640.  
  18641.  
  18642.  
  18643.  
  18644.  
  18645.  
  18646.  
  18647.  
  18648.  
  18649.  
  18650.  
  18651.  
  18652.  
  18653.  
  18654.  
  18655.  
  18656.  
  18657.  
  18658.  
  18659.  
  18660.  
  18661.  
  18662.  
  18663.  
  18664.  
  18665.  
  18666.  
  18667.          Page 297          The C Window Library               Page 297
  18668.  
  18669.                       GETTING VIDEO INFORMATION
  18670.                       -------------------------
  18671.  
  18672.          You can get information about the video configuration by
  18673.          calling the GetVideoBiosInfo() function.
  18674.  
  18675.  
  18676.          VIDEO_CONFIG structure
  18677.          ----------------------
  18678.  
  18679.          To get information about the video configuration, you must
  18680.          pass a pointer to a VIDEO_CONFIG structure.  This structure
  18681.          is defined as follows:
  18682.  
  18683.  
  18684.          typedef struct
  18685.          {
  18686.            unsigned int video_mode;          /* Current video mode */
  18687.            unsigned int cursor_startline;    /* Starting scan line of
  18688.                                                 cursor */
  18689.            unsigned int cursor_endline;      /* Ending scan line of
  18690.                                                 cursor */
  18691.            unsigned int cursor_row;          /* Screen row of cursor */
  18692.            unsigned int cursor_col;          /* Column of cursor */
  18693.            unsigned int video_page;          /* Current visible video
  18694.                                                 page */
  18695.            unsigned int video_pagesize;      /* Size in bytes of the
  18696.                                                  video page     */
  18697.            unsigned int video_rows;          /* Number of displayable
  18698.                                                 rows */
  18699.            unsigned int video_cols;          /* Number of displayable
  18700.                                                 columns *    /
  18701.            unsigned int char_height;         /* Height (in scan lines)
  18702.                                                 of a character  */
  18703.            unsigned int crt_port_address;    /* Address of CRT status
  18704.                                                 port */
  18705.            unsigned int crt_mode_setting;    /* Current CRT Mode
  18706.                                                 Setting   */
  18707.            unsigned int crt_color_setting;   /* Current CRT color
  18708.                                                 settings */
  18709.          } VIDEO_CONFIG;
  18710.  
  18711.  
  18712.  
  18713.          GetVideoBiosInfo()
  18714.          ------------------
  18715.  
  18716.          This function returns information about the current video
  18717.          configuration.  Here is the prototype:
  18718.  
  18719.                void GetVideoBiosInfo(VIDEO_CONFIG *v)
  18720.  
  18721.          The only argument is a pointer to a VIDEO_CONFIG structure.
  18722.          This structure is filled in with the appropriate values.
  18723.  
  18724.  
  18725.  
  18726.  
  18727.          Page 298          The C Window Library               Page 298
  18728.  
  18729.          Example:
  18730.  
  18731.          #include "window.h"
  18732.  
  18733.          VIDEO_CONFIG v;
  18734.  
  18735.          main()
  18736.          {
  18737.            WindowInitializeSystem();
  18738.  
  18739.            /* Get video information */
  18740.            ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  18741.            GetVideoBiosInfo(&v);
  18742.            VideoPrintf("The video mode is %d\n"
  18743.                        "The starting scan line of the cursor is %d\n"
  18744.                        "The ending scan line of the cursor is %d \n"
  18745.                        "The row of the cursor is %d \n"
  18746.                        "The column of the cursor is %d\n"
  18747.                        "The video page is %d\n"
  18748.                        "The size of the video page is %d\n"
  18749.                        "The number of rows is %d\n"
  18750.                        "The number of columns is %d\n"
  18751.                        "The height of the characters is %d\n",
  18752.                        v.video_mode, v.cursor_startline,
  18753.                        v.cursor_endline,
  18754.                        v.cursor_row,v.cursor_col,
  18755.                        v.video_page, v.video_pagesize,
  18756.                        v.video_rows, v.video_cols,
  18757.                        v.char_height);
  18758.          }
  18759.  
  18760.  
  18761.          There is no return value for GetVideoBiosInfo().
  18762.  
  18763.  
  18764.  
  18765.  
  18766.  
  18767.  
  18768.  
  18769.  
  18770.  
  18771.  
  18772.  
  18773.  
  18774.  
  18775.  
  18776.  
  18777.  
  18778.  
  18779.  
  18780.  
  18781.  
  18782.  
  18783.  
  18784.  
  18785.  
  18786.  
  18787.          Page 299          The C Window Library               Page 299
  18788.  
  18789.                             TIMED DELAYS
  18790.                             ------------
  18791.  
  18792.          One of the problems that has been addressed in The C Window
  18793.          Library is the lack of a delay() function in most C compiler
  18794.          packages.  The delay() function delays program execution for
  18795.          a certain number of milliseconds.  Borland's Turbo C compiler
  18796.          is one of the few that has a delay() function.  The other
  18797.          compilers may have a sleep() function, but usually these
  18798.          functions do not have millisecond accuracy.
  18799.  
  18800.          One of the problems was to write a delay() function that
  18801.          would work for all the major C compilers, work with
  18802.          millisecond accuracy, work for any speed PC, and last but not
  18803.          least, without using floating point arithmetic.  This
  18804.          function was written in assembly language for accuracy.  The
  18805.          use of the delay() is used extensively in displaying and
  18806.          hiding windows with certain special effects.
  18807.  
  18808.  
  18809.          delay()
  18810.          -------
  18811.  
  18812.          The delay() function delays the program for a certain number
  18813.          of milliseconds.  Here is the prototype:
  18814.  
  18815.                     void delay(unsigned millisecs)
  18816.  
  18817.          The only argument is the number of milliseconds to delay.  If
  18818.          you are using the Turbo C version of The C Window Library,
  18819.          this function is already included in the Turbo C library.
  18820.          However, if you are using another compiler you now have a
  18821.          delay() function!
  18822.  
  18823.  
  18824.          Example:
  18825.  
  18826.          main()
  18827.          {
  18828.            WindowInitializeSystem();
  18829.            delay(50);   /* Delay for 50 milliseconds */
  18830.          }
  18831.  
  18832.          You must call WindowInitializeSystem() before using delay().
  18833.  
  18834.          There is no return value for delay().
  18835.  
  18836.  
  18837.  
  18838.  
  18839.  
  18840.  
  18841.  
  18842.  
  18843.  
  18844.  
  18845.  
  18846.  
  18847.          Page 300          The C Window Library               Page 300
  18848.  
  18849.                            SOUND FUNCTIONS
  18850.                            ---------------
  18851.  
  18852.          The C Window Library also supports sound functions for
  18853.          compilers that are lacking these functions.
  18854.  
  18855.  
  18856.          sound() and nosound()
  18857.          ---------------------
  18858.  
  18859.          The sound() function sounds a tone with a specified frequency
  18860.          in Hertz (cycles per second).  Here is a prototype:
  18861.  
  18862.                      void sound(unsigned frequency)
  18863.  
  18864.          The nosound() function turns off the tone generated by the
  18865.          sound() function.
  18866.  
  18867.  
  18868.          Example:
  18869.  
  18870.          #include "window.h"
  18871.  
  18872.          main()
  18873.          {
  18874.            unsigned i;
  18875.            WindowInitializeSystem();
  18876.            for (i=100;i<=1000;i++)
  18877.              sound(i);
  18878.            for(i=1000;i>=100;i--)
  18879.              sound(i);
  18880.            nosound();
  18881.          }
  18882.  
  18883.          Note for Turbo users:
  18884.  
  18885.          You should include "dos.h" in your files that contain sound()
  18886.          and nosound().  All other compilers should include
  18887.          "window.h".
  18888.  
  18889.          Note for Power C users:  If you are using the Power C
  18890.          compiler, you must include "window.h" or any file that
  18891.          includes window.h after bios.h.  This is to ensure that the
  18892.          linker does not get confused with the Power C function
  18893.          called sound(), which works differently than the sound()
  18894.          function defined above.
  18895.  
  18896.  
  18897.  
  18898.          MakeSound()
  18899.          -----------
  18900.  
  18901.          The MakeSound() function sounds a tone for a duration of
  18902.          time.  Here is the prototype:
  18903.  
  18904.  
  18905.  
  18906.  
  18907.          Page 301          The C Window Library               Page 301
  18908.  
  18909.               void MakeSound(unsigned freq, unsigned millisec)
  18910.  
  18911.          where freq, is the frequency of the tone (in Hertz) and
  18912.          millisec is the number of milliseconds to sound the tone.
  18913.  
  18914.  
  18915.          Example:
  18916.          --------
  18917.  
  18918.          #include "window.h"
  18919.  
  18920.          main()
  18921.          {
  18922.            WindowInitializeSystem();
  18923.            /* Produce a 440 Hertz tone for 3 seconds */
  18924.            MakeSound(440,3000);
  18925.          }
  18926.  
  18927.          There is no error return for this function.
  18928.  
  18929.  
  18930.  
  18931.  
  18932.  
  18933.  
  18934.  
  18935.  
  18936.  
  18937.  
  18938.  
  18939.  
  18940.  
  18941.  
  18942.  
  18943.  
  18944.  
  18945.  
  18946.  
  18947.  
  18948.  
  18949.  
  18950.  
  18951.  
  18952.  
  18953.  
  18954.  
  18955.  
  18956.  
  18957.  
  18958.  
  18959.  
  18960.  
  18961.  
  18962.  
  18963.  
  18964.  
  18965.  
  18966.  
  18967.          Page 302          The C Window Library               Page 302
  18968.  
  18969.                            ERROR HANDLING
  18970.                            --------------
  18971.  
  18972.          Whenever an error has occurred in The C Window Library, a
  18973.          user defined error function can be called.
  18974.  
  18975.  
  18976.  
  18977.  
  18978.          The window_error_func function pointer
  18979.          --------------------------------------
  18980.  
  18981.          The window_error_func function pointer can point to an error
  18982.          function that is performed whenever there is an error
  18983.          encountered in one of The C Window Library functions.  If the
  18984.          global variable check_existence_flag is set to 1 and there is
  18985.          an error, The C Window Library will automatically call
  18986.          window_error_func.  Here is the prototype:
  18987.  
  18988.          void (*window_error_func)(int errcode, char *sourcefile,
  18989.                                    int sourceline, char *funcname)
  18990.  
  18991.          The errcode is one of the defined error codes included in The
  18992.          C Window Library.  Refer to page 6 of the main documentation
  18993.          for more information of the error codes and their
  18994.          definitions.  The second argument is the name of the file
  18995.          where the error occurred.  Only users with the source code to
  18996.          The C Window Library will have access to this file.  The
  18997.          third argument is the offending line in the source file of
  18998.          where the error occurred.  The last argument is the name of
  18999.          the function of where the error occurred.
  19000.  
  19001.          By default window_error_func points to a void null function
  19002.          (VOIDNULLFN), therefore no error function is called.
  19003.  
  19004.          Here is an example of how to implement automatic error
  19005.          checking:
  19006.  
  19007.          #include "window.h"
  19008.          #define WHITEONRED CREATE_VIDEO_ATTRIBUTE(red,white)
  19009.          void custom_error_func(int, char *, int, char *);
  19010.  
  19011.          WPOINTER w, error_window;
  19012.          void initialize_error();
  19013.          main()
  19014.          {
  19015.            WindowInitializeSystem();
  19016.            WindowSaveInitial(0);
  19017.            window_error_func = custom_error_func;  /* Assign error
  19018.                                                       function */
  19019.            initialize_error();
  19020.            WindowOpen(w);       /* will be flagged for an error */
  19021.          }
  19022.  
  19023.          void initialize_error()    /* Initialize error window and
  19024.                                        error handler */
  19025.  
  19026.  
  19027.          Page 303          The C Window Library               Page 303
  19028.  
  19029.          {
  19030.            error_window =
  19031.                  WindowInitialize(BORDER,1,1,60,5,WHITEONRED,
  19032.                                   WHITEONRED,SINGLEBOX);
  19033.            WindowOpen(error_window);
  19034.          }
  19035.  
  19036.  
  19037.          void custom_error_func(int errcode, char *sourcefile,
  19038.                                 int sourceline, char *funcname)
  19039.          {
  19040.            int ch;
  19041.            MakeSound(100,500);           /* Produce an error beep */
  19042.            if (errcode == NO_HEAP_MEM)   /* Always check for the heap
  19043.                                             memory error separately */
  19044.            {
  19045.              VideoWriteString("You have ran out of Heap Memory",1,1);
  19046.              VideoWriteString(
  19047.             "Press 'Q' to quit program, Any other key to Continue...",
  19048.                               2,1);
  19049.            }
  19050.  
  19051.            else                         /* Display error window */
  19052.            {
  19053.              WindowClear(error_window);
  19054.              WindowDisplay(error_window,1,EXPLODE);
  19055.              WindowPrintf(error_window,
  19056.               "Error Code: %d\nSource File: %s\nSource Line %d\n"
  19057.               "Error Occurred in %s",
  19058.                errcode,sourcefile,sourceline,funcname);
  19059.  
  19060.              WindowWriteString(error_window,
  19061.             "Press 'Q' to quit program, Any other key to Continue...",
  19062.                                5,1);
  19063.            }
  19064.  
  19065.            ch = GET_KEY();
  19066.            if (ch == 'Q' || ch == 'q')
  19067.              exit(0);
  19068.            else
  19069.            if (errcode != NO_HEAP_MEM)
  19070.              WindowHide(error_window,CONTRACT);
  19071.          }
  19072.  
  19073.  
  19074.          The above example initializes an error window and sets the
  19075.          window_error_func function pointer to point to the function
  19076.          custom_error_func().  Whenever an error occurs in The C
  19077.          Window Library, custom_error_func() will be called.
  19078.  
  19079.          Please note the check to see if the NO_HEAP_MEM error has
  19080.          occurred.  It is important that you check for this error
  19081.          condition separately.  The reason for this is that if there
  19082.          is not enough heap memory, you may inadvertently call a
  19083.          function in your error handler that calls on malloc() or any
  19084.  
  19085.  
  19086.  
  19087.          Page 304          The C Window Library               Page 304
  19088.  
  19089.          of the other memory allocation related functions.  This will
  19090.          either freeze your system, or more peculiarly, cause your
  19091.          error handler to be called in an infinite loop because of the
  19092.          repeated failing calls to malloc() or its related functions.
  19093.          In the latter case, you will run out of stack space.
  19094.  
  19095.          If you want to unassign the window_error_code function
  19096.          pointer, use the following line in your code:
  19097.  
  19098.                     window_error_func = VOIDNULLFN;
  19099.  
  19100.  
  19101.  
  19102.  
  19103.  
  19104.  
  19105.  
  19106.  
  19107.  
  19108.  
  19109.  
  19110.  
  19111.  
  19112.  
  19113.  
  19114.  
  19115.  
  19116.  
  19117.  
  19118.  
  19119.  
  19120.  
  19121.  
  19122.  
  19123.  
  19124.  
  19125.  
  19126.  
  19127.  
  19128.  
  19129.  
  19130.  
  19131.  
  19132.  
  19133.  
  19134.  
  19135.  
  19136.  
  19137.  
  19138.  
  19139.  
  19140.  
  19141.  
  19142.  
  19143.  
  19144.  
  19145.  
  19146.  
  19147.          Page 305          The C Window Library               Page 305
  19148.  
  19149.                USING A MOUSE WITH THE C WINDOW LIBRARY
  19150.                ---------------------------------------
  19151.  
  19152.          With The C Window Library, you can create applications that
  19153.          use a Microsoft compatible mouse to select from popup,
  19154.          pulldown, and bar menus as well as getting mouse presses.
  19155.          Using the mouse for menus will be discussed in this section,
  19156.          while getting and testing for button presses will be
  19157.          discussed in the KEYBOARD MACROS section below.
  19158.  
  19159.  
  19160.          Installing the Mouse Library
  19161.          ----------------------------
  19162.  
  19163.          Before using the mouse library, make sure that you read the
  19164.          README file concerning installing the mouse library.
  19165.  
  19166.  
  19167.          Include files
  19168.          -------------
  19169.  
  19170.          The only include file needed is cwlmouse.h.  This file also
  19171.          includes window.h.
  19172.  
  19173.  
  19174.          Initializing the Mouse with MouseInitializeSystem()
  19175.          ---------------------------------------------------
  19176.  
  19177.          Before you can use a mouse, you must initialize it by calling
  19178.          MouseInitializeSystem().  This function tests for a Microsoft
  19179.          compatible mouse and returns a value denoting whether a mouse
  19180.          is found.  Here is the prototype:
  19181.  
  19182.          int MouseInitializeSystem(int intype, int *button, int hpos,
  19183.                                    int vpos)
  19184.  
  19185.          The first argument informs MouseInitializeSystem() to whether
  19186.          you just want to test to see if a mouse is installed and not
  19187.          to activate the mouse, or to not only test for the mouse, but
  19188.          to activate it.  If the first argument is MOUSE_TEST,
  19189.          MouseInitializeSystem() will just return an integer denoting
  19190.          whether a mouse is found.  If the first argument is
  19191.          MOUSE_FULL_INSTALL, not only is a status returned, but the
  19192.          mouse will be activated.
  19193.  
  19194.          The second argument is a pointer to an integer that will
  19195.          contain the number of buttons that the mouse has.  This
  19196.          number will usually be 2 or 3.
  19197.  
  19198.          The third and fourth arguments are the screen coordinates of
  19199.          where to place the mouse cursor on the screen.  The third
  19200.          argument is the row, and the fourth argument is the column to
  19201.          place the mouse cursor.
  19202.  
  19203.          MouseInitializeSystem() returns NOMOUSE if a mouse is not
  19204.          installed, or MOUSEFOUND if a mouse is installed.
  19205.  
  19206.  
  19207.          Page 306          The C Window Library               Page 306
  19208.  
  19209.          MouseInitializeSystem() must be called after calling
  19210.          WindowInitializeSystem() for it to work properly.
  19211.  
  19212.  
  19213.  
  19214.          Turning off the mouse with MouseRestoreSystem()
  19215.          -----------------------------------------------
  19216.  
  19217.          Before terminating a program that has called
  19218.          MouseInitializeSystem() you should call MouseRestoreSystem().
  19219.          If you do not call MouseRestoreSystem(), the mouse will still
  19220.          be 'alive', even though the application has terminated.  Here
  19221.          is the prototype:
  19222.  
  19223.                        int MouseRestoreSystem(void)
  19224.  
  19225.          If the mouse was not initialized previously with
  19226.          MouseInitializeSystem(), MouseRestoreSystem() returns
  19227.          NOMOUSE, otherwise the return value is NO_ERROR.
  19228.  
  19229.          Example:
  19230.  
  19231.  
  19232.          #include "cwlmouse.h"
  19233.  
  19234.          main()
  19235.          {
  19236.  
  19237.             /* initialize mouse */
  19238.             MouseInitializeSystem();
  19239.             /* ... */
  19240.  
  19241.             /* turn off mouse */
  19242.             MouseRestoreSystem();
  19243.          }
  19244.  
  19245.  
  19246.          If you want to turn the mouse back on after calling
  19247.          MouseRestoreSystem(), you must call MouseInitializeSystem()
  19248.          again.
  19249.  
  19250.  
  19251.          Example:
  19252.  
  19253.          #include "cwlmouse.h"
  19254.  
  19255.          main()
  19256.          {
  19257.             int button;
  19258.             int ismouse;
  19259.             WindowInitializeSystem();
  19260.             ismouse = (MouseInitializeSystem(MOUSE_FULL_INSTALL,
  19261.                                     &button,1,1) == MOUSEFOUND));
  19262.             MoveCursor(1,1,0);
  19263.             if (ismouse)
  19264.  
  19265.  
  19266.  
  19267.          Page 307          The C Window Library               Page 307
  19268.  
  19269.               VideoPrintf(
  19270.               "Mouse was found.  Number of buttons is %d\n",button);
  19271.             else
  19272.               VideoPrintf("Mouse not found");
  19273.          }
  19274.  
  19275.  
  19276.  
  19277.          Using a mouse with popup menus
  19278.          ------------------------------
  19279.  
  19280.          Once the mouse is initialized, you can use the mouse to make
  19281.          selections with popup menus.
  19282.  
  19283.          To move the highlight bar with the mouse, position the mouse
  19284.          cursor over any menu entry in the window, and hold the left
  19285.          mouse button down.  If the mouse is moved while holding the
  19286.          left button down, the highlight is moved along with the mouse
  19287.          cursor.  A selection is made by releasing the left mouse
  19288.          button while the mouse cursor is on an active menu entry.
  19289.  
  19290.          You can also scroll through the menu entries by placing the
  19291.          mouse on either a down arrow or up arrow symbols on the popup
  19292.          menu window, and then holding the left mouse button down.  By
  19293.          default, the symbols appear at the bottom border of the
  19294.          window.  If the popup window is borderless, the
  19295.          POPUPMOUSESCROLL option is ignored.
  19296.  
  19297.          To activate the mouse so that it can be used for popup menus,
  19298.          you must set the popup option POPUPMOUSE on.  If you also
  19299.          want to use the scroll through option described above,
  19300.          POPUPMOUSESCROLL should also be turned on.
  19301.  
  19302.  
  19303.          Example:
  19304.  
  19305.  
  19306.          #include "menu.h"
  19307.          #include "cwlmouse.h"
  19308.          int menu_func();
  19309.  
  19310.          POPUP_MENU_ENTRY menu_items[] = {
  19311.                       " Load      F3",1,'L',F3,menu_func,
  19312.                       " Pick  Alt-F3",2,'P',ALTF3,menu_func,
  19313.                       " New"         ,3,'N',0,menu_func,
  19314.                       " Save      F2",4,'S',F2,menu_func,
  19315.                       " Write to    ",5,'W',0,menu_func,
  19316.                       " Directory   ",6,'D',0,menu_func,
  19317.                       " Change Dir"  ,7,'C',0,menu_func,
  19318.                       " OS shell"    ,8,'O',0,menu_func,
  19319.                       " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  19320.                       CWL_NULL,0};
  19321.          unsigned int menu_colors[5];
  19322.          POPUP_MENU_PTR p;
  19323.  
  19324.  
  19325.  
  19326.  
  19327.          Page 308          The C Window Library               Page 308
  19328.  
  19329.          main()
  19330.          {
  19331.            int b;
  19332.            WindowInitializeSystem();
  19333.            WindowSaveInitial(0);
  19334.                   /* Remember to save the initial screen */
  19335.            MouseInitiailizeSystem(MOUSE_FULL_INSTALL,&b,1,1);
  19336.           /* define colors */
  19337.            menu_colors[ENTRYCOLOR] =
  19338.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  19339.  
  19340.            menu_colors[BORDERCOLOR] =
  19341.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  19342.  
  19343.            menu_colors[HOTKEYCOLOR] =
  19344.                   CREATE_VIDEO_ATTRIBUTE(white,blue);
  19345.  
  19346.            menu_colors[HIGHLIGHTCOLOR] =
  19347.                   CREATE_VIDEO_ATTRIBUTE(cyan,black);
  19348.  
  19349.            menu_colors[UNAVAILCOLOR] =
  19350.                   CREATE_VIDEO_ATTRIBUTE(white,black);
  19351.  
  19352.           /* create a POPUP_MENU_PTR */
  19353.           p = PopupCreateMenu(menu_items,menu_colors, 1,1,6,
  19354.                          POPUPSTATIC | POPUPMOUSE | POPUPMOUSESCROLL,
  19355.                          WNULLFN,VWNULLFN);
  19356.  
  19357.           PopupSelectMenu(p,  /* POPUP_MENU_PTR */
  19358.                             1,  /* rank of popup window */
  19359.                             1   /* menu entry to start on */
  19360.                            );
  19361.           MouseRestoreSystem();
  19362.          }
  19363.  
  19364.  
  19365.          int menu_func(POPUP_MENU_PTR p, unsigned which)
  19366.          {
  19367.            WPOINTER w;
  19368.            w = WindowInitialize(BORDER,15,15,40,4,
  19369.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  19370.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  19371.                                 SINGLEBOX);
  19372.            WindowOpen(w);
  19373.            WindowClear(w);
  19374.            WindowPrintf(w,"You have selected %s",
  19375.                         POPUP_ENTRY_STRING(p,which));
  19376.            WindowWriteCenterString(w,"Press a key to continue",3);
  19377.            WindowDisplay(w,1,NOEFFECT);
  19378.            GET_KEY();
  19379.            WindowFree(w,NOEFFECT);
  19380.            if (which == 9)
  19381.              return POPUP_EXIT;
  19382.            else
  19383.            return POPUP_CONTINUE;
  19384.          }
  19385.  
  19386.  
  19387.          Page 309          The C Window Library               Page 309
  19388.  
  19389.          The above example uses the popup menu option POPUPMOUSE and
  19390.          POPUPMOUSESCROLL options in the PopupCreateMenu() function.
  19391.          Also note the call to MouseInitializeSystem() to initialize
  19392.          the mouse system.  You must use the constant
  19393.          MOUSE_FULL_INSTALL in the MouseInitializeSystem() function to
  19394.          make sure that the POPUPMOUSE and the POPUPMOUSESCROLL
  19395.          options will take effect.  If a mouse does not exist, or the
  19396.          mouse is not activated, POPUPMOUSE and POPUPMOUSESCROLL will
  19397.          be ignored.  Also note that the include file cwlmouse.h was
  19398.          included.  These are the only changes needed for mouse
  19399.          support for the popup menus.
  19400.  
  19401.  
  19402.  
  19403.          Popup Menu's pre-function for mouse
  19404.          -----------------------------------
  19405.  
  19406.          When the POPUPMOUSESCROLL option is used for popup menus, the
  19407.          menu can be scrolled automatically by placing the mouse on
  19408.          either the up or down scroll characters on the popup window,
  19409.          and pressing the left mouse button.
  19410.  
  19411.          The normal pre-function for the popup menu, namely the
  19412.          function pointed to by global_popup_prefunc, is disabled if
  19413.          you use the mouse to scroll through the entries in the manner
  19414.          described above.  If you want to perform a function when the
  19415.          menu bar is moved automatically from choice to choice, you
  19416.          should use the popup_mouse_move_func function pointer.  Here
  19417.          is the prototype:
  19418.  
  19419.          void (*popup_mouse_move_func)(POPUP_MENU_PTR p,
  19420.                                        unsigned current)
  19421.  
  19422.          p is the current popup menu, and current is the current
  19423.          selection that the highlight bar is on.
  19424.  
  19425.          Note the difference in the second argument.  The
  19426.          global_popup_prefunc function pointer has a pointer to an
  19427.          integer as the second argument, while the
  19428.          popup_mouse_move_func has an integer as the second argument.
  19429.          Also note that the popup_mouse_move_func returns nothing,
  19430.          while the global_popup_prefunc returns a value back to the
  19431.          menu manager.
  19432.  
  19433.          If you use the mouse the 'normal' way (pointing the mouse to
  19434.          the actual menu entry and moving the mouse up or down while
  19435.          holding the left mouse button down), the normal pre-function
  19436.          is not disabled.
  19437.  
  19438.          The reason for having the popup_mouse_move_func function
  19439.          pointer is that there may be a description displayed for each
  19440.          menu entry, where the displaying of the menu entry is done by
  19441.          the function pointed to by global_popup_prefunc.  Here is a
  19442.          small example:
  19443.  
  19444.  
  19445.  
  19446.  
  19447.          Page 310          The C Window Library               Page 310
  19448.  
  19449.          #include "menu.h"
  19450.          #include "cwlmouse.h"
  19451.          int display_choice();
  19452.          void do_display_choice();
  19453.  
  19454.          POPUP_MENU_PTR p;
  19455.          /* other initializations */
  19456.  
  19457.          main()
  19458.          {
  19459.            WindowInitializeSystem();
  19460.            WindowSaveInitial();
  19461.            MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,1,1);
  19462.            p = PopupCreateMenu(/* arguments */);
  19463.            PopupSetOptions(p,POPUPMOUSE|POPUPMOUSESCROLL,1);
  19464.            global_popup_prefunc = display_choice;
  19465.            popup_move_mouse_func = do_display_choice;
  19466.  
  19467.            /*
  19468.                ...
  19469.  
  19470.                   */
  19471.  
  19472.          }
  19473.  
  19474.          display_choice(POPUP_MENU_PTR p, int *choice)
  19475.          {
  19476.             /* display info for entry in a window */
  19477.             return POPUP_CONTINUE;
  19478.          }
  19479.  
  19480.  
  19481.          void do_display_choice(POPUP_MENU_PTR p, int choice)
  19482.          {
  19483.            display_choice(p,&choice);
  19484.          }
  19485.  
  19486.  
  19487.          Using a mouse with bar menus
  19488.          ----------------------------
  19489.  
  19490.          To move the highlight bar with the mouse, position the mouse
  19491.          cursor over any menu entry in the window, and hold the left
  19492.          mouse button down.  If the mouse is moved while holding the
  19493.          left button down, the highlight is moved along with the mouse
  19494.          cursor.  A selection is made by releasing the left mouse
  19495.          button while the mouse cursor is on an active menu entry.
  19496.  
  19497.          To activate the mouse so that it can be used for bar menus,
  19498.          you must set the bar menu option BARMOUSE on.
  19499.  
  19500.  
  19501.  
  19502.  
  19503.  
  19504.  
  19505.  
  19506.  
  19507.          Page 311          The C Window Library               Page 311
  19508.  
  19509.          Example:
  19510.  
  19511.          #include "menu.h"
  19512.          #include "cwlmouse.h"
  19513.  
  19514.          int menu_func();
  19515.  
  19516.          BAR_MENU_ENTRY bar_items[] = {
  19517.                               "File",1,4,'F',ALTF,menu_func,
  19518.                               "Edit",1,10,'E',0,menu_func,
  19519.                               "Run",1,17,'R',0,menu_func,
  19520.                               "Compile",1,23,'C',0,menu_func,
  19521.                               "Project",1,33,'P',0,menu_func,
  19522.                               "Options", 1,43,'O',0,menu_func,
  19523.                               "Debug",1,53,'D',0,menu_func,
  19524.                               "Break/watch",1,61,'B',0,menu_func,
  19525.                               CWL_NULL};
  19526.  
  19527.          unsigned int menu_colors[5];
  19528.          BAR_MENU_PTR b;
  19529.  
  19530.          main()
  19531.          {
  19532.            int b;
  19533.            WindowInitializeSystem();
  19534.            WindowSaveInitial(0);
  19535.            MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,1,1);
  19536.  
  19537.            menu_colors[ENTRYCOLOR] =
  19538.                       CREATE_VIDEO_ATTRIBUTE(white,black);
  19539.  
  19540.            menu_colors[BORDERCOLOR] =
  19541.                       CREATE_VIDEO_ATTRIBUTE(white,black);
  19542.  
  19543.            menu_colors[HOTKEYCOLOR] =
  19544.                       CREATE_VIDEO_ATTRIBUTE(white,blue);
  19545.  
  19546.            menu_colors[HIGHLIGHTCOLOR] =
  19547.                       CREATE_VIDEO_ATTRIBUTE(cyan,black);
  19548.  
  19549.            menu_colors[UNAVAILCOLOR] =
  19550.                       CREATE_VIDEO_ATTRIBUTE(white,black);
  19551.  
  19552.           /* create a BAR_MENU_PTR */
  19553.            b = BarCreateMenu(bar_items,menu_colors, 1,1,
  19554.                              BARSTATIC | BARWRAP | BARMOUSE,WNULLFN);
  19555.            BarSelectMenu(b,1,1);
  19556.            MouseRestoreSystem();
  19557.          }
  19558.  
  19559.  
  19560.  
  19561.  
  19562.  
  19563.  
  19564.  
  19565.  
  19566.  
  19567.          Page 312          The C Window Library               Page 312
  19568.  
  19569.          int menu_func(BAR_MENU_PTR b, unsigned which)
  19570.          {
  19571.            WPOINTER w;
  19572.            w = WindowInitialize(BORDER,15,15,40,4,
  19573.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  19574.                                 CREATE_VIDEO_ATTRIBUTE(black,white),
  19575.                                 SINGLEBOX);
  19576.            WindowOpen(w);
  19577.            WindowPrintf(w,"You have selected %s",
  19578.                         BAR_ENTRY_STRING(b,which));
  19579.            WindowWriteCenterString(w,"Press a key to continue",3);
  19580.            WindowDisplay(w,1,NOEFFECT);
  19581.            GET_KEY();
  19582.            WindowFree(w,NOEFFECT);
  19583.            if (which == 9)
  19584.              return BAR_EXIT;
  19585.            else return BAR_CONTINUE;
  19586.          }
  19587.  
  19588.          The above example uses the bar menu option BARMOUSE option in
  19589.          the BarCreateMenu() function.  Also note the call to
  19590.          MouseInitializeSystem() to initialize the mouse system.  You
  19591.          must use the constant MOUSE_FULL_INSTALL in the
  19592.          MouseInitializeSystem() function to make sure that the
  19593.          BARMOUSE option will take effect.  If a mouse does not exist,
  19594.          or the mouse is not activated, BARMOUSE will be ignored.
  19595.          Also note that the include file cwlmouse.h was included.
  19596.          These are the only changes needed for mouse support for the
  19597.          bar menus.
  19598.  
  19599.  
  19600.  
  19601.          Using a mouse with pulldown menus
  19602.          ---------------------------------
  19603.  
  19604.          If the menu options for the mouse are turned on for all popup
  19605.          menus and the bar menu, and these menus are used as part of a
  19606.          pulldown menu system, the mouse behaves exactly the same
  19607.          except for the following differences:
  19608.  
  19609.            a) Holding the left mouse button down and positioning the
  19610.               mouse cursor over a bar menu entry will bring up the
  19611.               popup menu that is associated with the bar entry.  If
  19612.               there is no popup menu defined for a particular bar
  19613.               entry, releasing the mouse button will invoke the
  19614.               entry's function.
  19615.  
  19616.  
  19617.            b) Releasing the mouse button when it is positioned over a
  19618.               bar entry, and the bar entry has a popup associated with
  19619.               it, does nothing.  A general rule is that a menu
  19620.               function is only executed when the highlight bar is
  19621.               positioned on a menu entry that has a function
  19622.               associated with it.
  19623.  
  19624.  
  19625.  
  19626.  
  19627.          Page 313          The C Window Library               Page 313
  19628.  
  19629.          Changing the mouse defaults
  19630.          ---------------------------
  19631.  
  19632.          By default, the left mouse button is held down when moving
  19633.          the highlight bar.  If you prefer a different button to be
  19634.          used to move the highlight bar, you can change the button by
  19635.          changing the following global variables:
  19636.  
  19637.              int popmenu_button_press - holds the current button to be
  19638.              used to move the highlight bar in popup menus.
  19639.  
  19640.              int barmenu_button_press - holds the current button to be
  19641.              used to move the highlight bar in bar menus.
  19642.  
  19643.          The following constants can be assigned to these two global
  19644.          variables:
  19645.  
  19646.                      Constant              Definition
  19647.                      --------              ----------
  19648.                     MOUSELEFT_PRESS        Left button.
  19649.                     MOUSERIGHT_PRESS       Right button.
  19650.                     MOUSEMIDDLE_PRESS      Middle button.
  19651.  
  19652.          By default, popmenu_button_press and barmenu_button_press are
  19653.          assigned MOUSELEFT_PRESS.  Here is an example of changing
  19654.          these variables:
  19655.  
  19656.          #include "cwlmouse.h"
  19657.          #include "menu.h"
  19658.  
  19659.          main()
  19660.          {
  19661.               ...
  19662.  
  19663.            MouseInitializeSystem(  /* arguments */ );
  19664.            /* change mouse menu buttons */
  19665.            popmenu_button_press = MOUSERIGHT_PRESS;
  19666.            barmenu_button_press = MOUSERIGHT_PRESS;
  19667.               ...
  19668.          }
  19669.  
  19670.          The popmenu_button_press and barmenu_button_press variables
  19671.          are assigned their default values when
  19672.          MouseInitializeSystem() is called.  If you want to change
  19673.          these variables, make sure that the change is made after
  19674.          calling MouseInitializeSystem().
  19675.  
  19676.  
  19677.  
  19678.  
  19679.  
  19680.  
  19681.  
  19682.  
  19683.  
  19684.  
  19685.  
  19686.  
  19687.          Page 314          The C Window Library               Page 314
  19688.  
  19689.                   WINDOW AND VIRTUAL WINDOW MACROS
  19690.                   --------------------------------
  19691.  
  19692.          Note : These macros should be used after making a call to
  19693.          WindowInitializeSystem() or else unpredictable values will be
  19694.          returned.
  19695.  
  19696.  
  19697.          The following macros are defined in the window.h file.
  19698.          The window w is NOT CHECKED for validity.
  19699.  
  19700.  
  19701.          ISBORDER(w)    -  Returns 1 if window has a border, 0
  19702.                            otherwise.
  19703.  
  19704.          ISWRAP(w)      -  Returns 1 if window wrap is on, 0
  19705.                            otherwise.
  19706.  
  19707.          ISOPEN(w)      -  Returns 1 if window has been opened for
  19708.                            read/write, 0 otherwise.
  19709.  
  19710.          ISVISIBLE(w)   -  Returns 1 if window is visible, 0
  19711.                            otherwise.
  19712.  
  19713.          ISVIEWPORT(w)  -  Returns 1 if window is a viewport, 0
  19714.                            otherwise.
  19715.  
  19716.          ISWINDOW(vw)   -  Returns 1 if virtual window has any
  19717.                            viewports, 0 otherwise.
  19718.  
  19719.          ISBUFSAVE(w)   -  Returns 1 if text buffer for window was
  19720.                            successfully, allocated, 0 otherwise.
  19721.  
  19722.          ISSEETHRU(w)   -  Returns 1 if window is in see-thru mode, 0
  19723.                            otherwise.
  19724.  
  19725.          ISFROZEN(w)    -  Returns 1 if window is frozen from doing
  19726.                            screen updates when the virtual window has
  19727.                            changed, 0 otherwise.
  19728.  
  19729.          ISSHADOW(w)    -  Returns 1 if the window has a shadow, 0
  19730.                            otherwise.
  19731.  
  19732.          ISSHADOWTRANS(w) - Returns 1 if the shadow is transparent, 0
  19733.                             otherwise.
  19734.  
  19735.          SHADOW_POS(w) -   Returns the position of the shadow as an
  19736.                            integer.  The valid positions are as
  19737.                            follows:
  19738.  
  19739.                           Shadow Position                Return Value
  19740.                           ---------------                ------------
  19741.                             SHADOWUPLEFT                       1
  19742.                             SHADOWUPRIGHT                      2
  19743.                             SHADOWLOWLEFT                      3
  19744.  
  19745.  
  19746.  
  19747.          Page 315          The C Window Library               Page 315
  19748.  
  19749.                             SHADOWLOWRIGHT                     4
  19750.  
  19751.                             If there is no shadow, a 0 is returned.
  19752.  
  19753.          SHADOW_CHAR(w) -  Returns the current character used to draw
  19754.                            the window's shadow.  Return value is
  19755.                            undefined if the window has no shadow.
  19756.  
  19757.  
  19758.          SHADOW_ATTR(w) -  Returns the current video attribute used to
  19759.                            draw the window's shadow.  Return value is
  19760.                            undefined if the window has no shadow
  19761.  
  19762.          SHADOW_WIDTH(w) - Returns the width of the window's shadow.
  19763.                            Return value is undefined if the window has
  19764.                            no shadow.
  19765.  
  19766.          SHADOW_HEIGHT(w) - Returns the height of the window's shadow.
  19767.                             Return value is undefined if the window
  19768.                             has no shadow.
  19769.  
  19770.  
  19771.          VIRTUAL_ATTRIBUTE_ON(vw) - Returns 1 if the virtual window vw
  19772.                                     is attributed, 0 otherwise.
  19773.  
  19774.          VIRTUAL_WINDOW_EXIST(vw) - Returns 1 if virtual window was
  19775.                                     initialized, 0 otherwise.
  19776.  
  19777.          VIRTUAL_HEIGHT(vw) - Returns the number of rows in a virtual
  19778.                               window vw.
  19779.  
  19780.          VIRTUAL_WIDTH(vw) - Returns the number of columns in a
  19781.                              virtual window.
  19782.  
  19783.          VIRTUAL_WINDOW(w) - Returns the virtual window that the
  19784.                              viewport w is currently viewing.
  19785.  
  19786.          VIEWPORT_ROW(w) - Returns the upper left row of where the
  19787.                            viewport w is positioned on the virtual
  19788.                            window.
  19789.  
  19790.          VIEWPORT_COLUMN(w) - Returns the upper left column of where
  19791.                               the viewport w is positioned on the
  19792.                               virtual window.
  19793.  
  19794.          VIRTUAL_COORD_IN_VIEWPORT(w,row,col) - Returns 1 if the
  19795.                                virtual window coordinates (row,col)
  19796.                                are inside the viewport w, 0
  19797.                                otherwise.  The virtual window must
  19798.                                have w as a viewport.
  19799.  
  19800.          WINDOW_BORDER_CHARS(w) - Returns the current border of a
  19801.                                   window as a string.
  19802.  
  19803.  
  19804.  
  19805.  
  19806.  
  19807.          Page 316          The C Window Library               Page 316
  19808.  
  19809.          WINDOW_BORDER_COLOR(w) - Returns the border color of the
  19810.                                   window w.
  19811.  
  19812.  
  19813.          WINDOW_COLUMN(w) - Returns the absolute column of the upper
  19814.                             left hand corner of the window.
  19815.  
  19816.          WINDOW_EXIST(w)  - Returns 1 if window was initialized, 0
  19817.                             otherwise.
  19818.  
  19819.          WINDOW_HEIGHT(w) - Returns the height of the text area of the
  19820.                             window w.
  19821.  
  19822.  
  19823.          WINDOW_PAGENUM(w) - Returns the video page of where the
  19824.                              window will be displayed.
  19825.  
  19826.          WINDOW_RANK(w) - Returns the rank of the window w.
  19827.  
  19828.  
  19829.          WINDOW_ROW(w) - Returns the absolute row coordinate of the
  19830.                          upper left hand corner of the window w.
  19831.  
  19832.  
  19833.  
  19834.  
  19835.  
  19836.  
  19837.  
  19838.  
  19839.  
  19840.  
  19841.  
  19842.  
  19843.  
  19844.  
  19845.  
  19846.  
  19847.  
  19848.  
  19849.  
  19850.  
  19851.  
  19852.  
  19853.  
  19854.  
  19855.  
  19856.  
  19857.  
  19858.  
  19859.  
  19860.  
  19861.  
  19862.  
  19863.  
  19864.  
  19865.  
  19866.  
  19867.          Page 317          The C Window Library               Page 317
  19868.  
  19869.                              MENU MACROS
  19870.                              -----------
  19871.  
  19872.          The following macros are defined in the header file menu.h.
  19873.  
  19874.  
  19875.          Popup Menu Macros
  19876.          -----------------
  19877.  
  19878.          POPUP_CONFIRM_ON(p) - Returns 1 if the POPUP_MENU_PTR p has
  19879.                                the confirmation for hotkey selections
  19880.                                on, 0 otherwise.
  19881.  
  19882.          POPUP_DISPLAY_ON(p) - Returns 1 if the POPUP_MENU_PTR p's
  19883.                                window is to be displayed regardless if
  19884.                                the menu manager has returned to the
  19885.                                calling function, 0 otherwise.
  19886.  
  19887.          POPUP_ENHANCED_ON(p) - Returns 1 if the popup menu will
  19888.                                 recognize enhanced keys, 0 otherwise.
  19889.  
  19890.          POPUP_ENTRY_STRING(p,entry) - Returns the entry string of
  19891.                                        POPUP_MENU_ENTRY entry.
  19892.  
  19893.          POPUP_EXPLODE(p) -    Returns the special effect constant of
  19894.                                the POPUP_MENU_PTR p.  This special
  19895.                                effect is used to hide, close, and open
  19896.                                the popup menu's window.
  19897.  
  19898.          POPUP_MOUSE_ON(p) -   Returns 1 if a mouse can be used to
  19899.                                make selections, 0 otherwise.
  19900.  
  19901.          POPUP_MOUSE_SCROLL_ON(p) - Returns 1 if a mouse can be used
  19902.                                     to scroll through the entries if
  19903.                                     the entries cannot fit in the
  19904.                                     popup window, 0 otherwise.
  19905.  
  19906.          POPUP_NUMBER_OF_ENTRIES(p) - Returns the total number of
  19907.                                       entries defined in the
  19908.                                       POPUP_MENU_PTR p.
  19909.  
  19910.          POPUP_OVERRIDE_ON(p) - Returns 1 if POPUP_MENU_PTR p will
  19911.                                 have unavailable options processed, 0
  19912.                                 otherwise.
  19913.  
  19914.          POPUP_PULLDOWN_ON(p) - Returns 1 if the POPUP_MENU_PTR p is
  19915.                                 incorporated in a pulldown menu
  19916.                                 system, 0 otherwise.
  19917.  
  19918.          POPUP_SCROLL_UP_CHAR(p) - This is the scroll up character
  19919.                                    that is displayed if the
  19920.                                    POPUPMOUSESCROLL option is on for
  19921.                                    the popup menu p.  The default
  19922.                                    character is the up arrow.
  19923.  
  19924.  
  19925.  
  19926.  
  19927.          Page 318          The C Window Library               Page 318
  19928.  
  19929.          POPUP_SCROLL_DOWN_CHAR(p) - This is the scroll down character
  19930.                                      that is displayed if the
  19931.                                      POPUPMOUSESCROLL option is on for
  19932.                                      the popup menu p.  The default
  19933.                                      character is the down arrow.
  19934.  
  19935.          POPUP_SCROLL_UP_ATTR(p) - This is the color attribute for the
  19936.                                    scroll up character that is
  19937.                                    displayed if the POPUPMOUSESCROLL
  19938.                                    option is on for the popup menu p.
  19939.                                    The default character is the
  19940.                                    attribute of the popup window.
  19941.  
  19942.          POPUP_SCROLL_DOWN_ATTR(p) - This is the color attribute for
  19943.                                      the scroll down character that is
  19944.                                      displayed if the POPUPMOUSESCROLL
  19945.                                      option is on for the popup menu
  19946.                                      p.  The default character is the
  19947.                                      attribute of the popup window.
  19948.  
  19949.          POPUP_SCROLL_UP_ROW(p) - This is the row that the scroll up
  19950.                                   character is displayed in the popup
  19951.                                   window.  The default is the bottom
  19952.                                   border of the window
  19953.  
  19954.          POPUP_SCROLL_UP_COLUMN(p) - This is the column that the
  19955.                                      scroll up character is displayed
  19956.                                      in the popup window.  The default
  19957.                                      is column 1.
  19958.  
  19959.          POPUP_SCROLL_DOWN_ROW(p) - This is the row that the scroll
  19960.                                     down character is displayed in the
  19961.                                     popup window.  The default is the
  19962.                                     bottom border of the window
  19963.  
  19964.          POPUP_SCROLL_DOWN_COLUMN(p) - This is the column that the
  19965.                                        scroll down character is
  19966.                                        displayed in the popup window.
  19967.                                        The default is column 1.
  19968.  
  19969.          POPUP_STATIC_ON(p) -  Returns 1 if the POPUP_MENU_PTR p will
  19970.                                remain on the screen when an entry is
  19971.                                selected, 0 otherwise.
  19972.  
  19973.          POPUP_STRING_IN_WINDOW(p,entry) - Returns 1 if the
  19974.                            POPUP_MENU_PTR p has entry number entry
  19975.                            displayed in the popup menu's window, 0
  19976.                            otherwise.  This macro is useful if you
  19977.                            have a scrolling popup menu and want to
  19978.                            know if a particular entry is displayed in
  19979.                            the window.
  19980.  
  19981.          POPUP_VIRTUAL_WINDOW(p) - Returns the VWPOINTER of the popup
  19982.                                    menu.
  19983.  
  19984.  
  19985.  
  19986.  
  19987.          Page 319          The C Window Library               Page 319
  19988.  
  19989.          POPUP_WINDOW(p) - Returns the WPOINTER of the popup menu.
  19990.  
  19991.          POPUP_WRAP_ON(p) -    Returns 1 if the highlight wrap of
  19992.                                POPUP_MENU_PTR p is on, otherwise 0.
  19993.  
  19994.  
  19995.  
  19996.          Bar Menu Macros
  19997.          ---------------
  19998.  
  19999.          BAR_CONFIRM_ON(b) - Returns 1 if the BAR_MENU_PTR b has the
  20000.                              confirmation for hotkey selections on, 0
  20001.                              otherwise.
  20002.  
  20003.          BAR_DISPLAY_ON(b) - Returns 1 if the BAR_MENU_PTR b's window
  20004.                              is to be displayed regardless if the menu
  20005.                              manager has returned to the calling
  20006.                              function, 0 otherwise.
  20007.  
  20008.          BAR_ENHANCED_ON(b) - Returns 1 if the bar menu will recognize
  20009.                               enhanced keys, 0 otherwise.
  20010.  
  20011.          BAR_ENTRY_AVAILABLE(b,entry) - Returns 1 if the
  20012.                                         BAR_MENU_ENTRY entry is
  20013.                                         available, 0 otherwise.
  20014.  
  20015.          BAR_ENTRY_STRING(b,entry) - Returns the entry string of
  20016.                                      BAR_MENU_ENTRY entry.
  20017.  
  20018.          BAR_EXPLODE(b) -  Returns the special effect constant of the
  20019.                            BAR_MENU_PTR b.  This special effect is
  20020.                            used to hide, close, and open the popup
  20021.                            menu's window.
  20022.  
  20023.          BAR_NUMBER_OF_ENTRIES(b) - Returns the total number of
  20024.                                     entries defined in the
  20025.                                     BAR_MENU_PTR b.
  20026.  
  20027.          BAR_OVERRIDE_ON(b) - Returns 1 if BAR_MENU_PTR b will have
  20028.                               unavailable options processed, 0
  20029.                               otherwise.
  20030.  
  20031.          BAR_PULLDOWN_ON(b) - Returns 1 if the BAR_MENU_PTR b is
  20032.                               incorporated in a pulldown menu system,
  20033.                               0 otherwise.
  20034.  
  20035.          BAR_STATIC_ON(b) -  Returns 1 if the BAR_MENU_PTR b will
  20036.                              remain on the screen when an entry is
  20037.                              selected, 0 otherwise.
  20038.  
  20039.          BAR_WINDOW(b) - Returns the WPOINTER of the bar menu.
  20040.  
  20041.          BAR_WRAP_ON(b) -    Returns 1 if the highlight wrap of
  20042.                              BAR_MENU_PTR b is on, otherwise 0.
  20043.  
  20044.  
  20045.  
  20046.  
  20047.          Page 320          The C Window Library               Page 320
  20048.  
  20049.          Pulldown Menu Macros
  20050.          --------------------
  20051.  
  20052.          BAR_MENU_PTR_FROM_POPUP(pop) - Returns the BAR_MENU_PTR
  20053.                                         associated with the
  20054.                                         POPUP_MENU_PTR pop, which must
  20055.                                         be part of a pulldown menu
  20056.                                         system.
  20057.  
  20058.          BAR_MENU_PTR_FROM_PULLDOWN(pull) - Returns the BAR_MENU_PTR
  20059.                                             assocated with the
  20060.                                             PULLDOWN_MENU_PTR pull.
  20061.  
  20062.          POPUP_MENU_PTR_FROM_BAR(b,entry) - Returns the POPUP_MENU_PTR
  20063.                              associated with the BAR_MENU_PTR b.  The
  20064.                              entry argument is the number of the
  20065.                              POPUP_MENU_PTR desired in the pulldown
  20066.                              menu system.  For example, if you want to
  20067.                              know the first POPUP_MENU_PTR given only
  20068.                              a BAR_MENU_PTR, the call to this macro
  20069.                              would be POPUP_MENU_PTR_FROM_BAR(b,1).
  20070.  
  20071.          POPUP_MENU_PTR_FROM_PULLDOWN(pull,entry) - Returns the
  20072.                              POPUP_MENU_PTR associated with the
  20073.                              PULLDOWN_MENU_PTR pull.  The entry is the
  20074.                              number of the desired POPUP_MENU_PTR
  20075.                              desired in the pulldown menu system.
  20076.  
  20077.          PULLDOWN_MENU_PTR_FROM_BAR(b) - Returns the PULLDOWN_MENU_PTR
  20078.                                          associated with the bar menu
  20079.                                          b.
  20080.  
  20081.  
  20082.          PULLDOWN_MENU_PTR_FROM_POPUP(pop) - Returns the
  20083.                                              PULLDOWN_MENU_PTR
  20084.                                              associated with the
  20085.                                              POPUP_MENU_PTR pop.
  20086.  
  20087.  
  20088.  
  20089.  
  20090.  
  20091.  
  20092.  
  20093.  
  20094.  
  20095.  
  20096.  
  20097.  
  20098.  
  20099.  
  20100.  
  20101.  
  20102.  
  20103.  
  20104.  
  20105.  
  20106.  
  20107.          Page 321          The C Window Library               Page 321
  20108.  
  20109.                             VIDEO MACROS
  20110.                             ------------
  20111.  
  20112.          The following macros are defined in the vidsys.h file.  Note:
  20113.          by including window.h in your source files, vidsys.h is
  20114.          automatically included.
  20115.  
  20116.          CHECK_SNOW - Returns 1 if during direct screen writes that
  20117.                       video "snow" is eliminated.  You can also assign
  20118.                       values to this macro.  This macro is a pseudonym
  20119.                       for the variable chksnow_.
  20120.  
  20121.                       Example:
  20122.                        #include "vidsys.h"
  20123.                            ...
  20124.                        int a;
  20125.                        a = CHECK_SNOW;  /* Returns 1 if snow checking
  20126.                                            on,
  20127.                                            0 otherwise */
  20128.                        CHECK_SNOW = 0;  /* Turn off snow checking */
  20129.  
  20130.          CREATE_VIDEO_ATTRIBUTE(bg,fg) - creates a video attribute
  20131.                          using bg as the background color, and fg as
  20132.                          the foreground color.  The following
  20133.                          variables can be used:
  20134.  
  20135.              Variable
  20136.                Name            Color          Value
  20137.              -------           -----          -----
  20138.  
  20139.                black           Black            0
  20140.                blue            Blue             1
  20141.                green           Green            2
  20142.                cyan            Cyan             3
  20143.                red             Red              4
  20144.                magenta         Magenta          5
  20145.                brown           Brown            6
  20146.                white           White            7
  20147.                gray            Gray             8
  20148.                lightblue       Light Blue       9
  20149.                lightgreen      Light green     10
  20150.                lightcyan       Light cyan      11
  20151.                lightred        Light red       12
  20152.                lightmagenta    Light magenta   13
  20153.                yellow          Yellow          14
  20154.                lightwhite      Intense white   15
  20155.  
  20156.  
  20157.  
  20158.  
  20159.  
  20160.          The variables above are initialized when
  20161.          WindowInitializeSystem() is called.  If you want to use a
  20162.          color value before WindowInitializeSystem() is called, you
  20163.          can use the uppercase equivalent of the above variables, with
  20164.  
  20165.  
  20166.  
  20167.          Page 322          The C Window Library               Page 322
  20168.  
  20169.          a trailing underscore character attached to the name.  For
  20170.          example BLACK_ would be used instead of black, WHITE_ would
  20171.          be used instead of white, etc.  For monochrome systems, the
  20172.          only colors that are available are black, white, and intense
  20173.          white.  An attribute of blue creates an underline attribute,
  20174.          and light blue creates an intense underlined attribute.  Any
  20175.          other combination on a monochrome system is undefined.
  20176.  
  20177.  
  20178.          GET_BGROUND_COLOR(c) - Returns the background color of the
  20179.                                 video attribute c.
  20180.  
  20181.          GET_FGROUND_COLOR(c) - Returns the foreground color of the
  20182.                                 video attribute c.
  20183.  
  20184.          GET_OFFSET(x) -  Returns the offset of a pointer x.  The
  20185.                           pointer can be either near or far.
  20186.  
  20187.          GET_SEGMENT(x) - Returns the segment address of a pointer x.
  20188.                           The pointer can be either near or far.
  20189.  
  20190.          MAKE_FAR_POINTER(a,b) - Creates a far pointer made up of
  20191.                                  segment address a, and offset address
  20192.                                  b.
  20193.  
  20194.          SCREEN_OFFSET(r,c,a) -  Returns the screen offset of the
  20195.                                  address of a character located at row
  20196.                                  r and column c of the video page a.
  20197.                                  The screen segment is defined in the
  20198.                                  macro SCREEN_SEGMENT.  both r and c
  20199.                                  should be >= 1.
  20200.  
  20201.             Example:  char far *p;
  20202.             p = MAKE_FAR_POINTER(SCREEN_SEGMENT,SCREEN_OFFSET(1,1,0));
  20203.  
  20204.             The above example has created a far pointer p that points
  20205.             to the screen buffer memory at row 1, column 1, on video
  20206.             page 0.
  20207.  
  20208.          SCREEN_OFFSET_ATTR(r,c,a) - Returns the screen offset of the
  20209.                               address of a attribute located at row r
  20210.                               and column c of the video page a.  The
  20211.                               screen segment is defined in the macro
  20212.                               SCREEN_SEGMENT. both r and c should be
  20213.                               >= 1.
  20214.  
  20215.          SCREEN_SEGMENT - Returns the screen segment of video page 0.
  20216.                           This macro is a pseudonym for the variable
  20217.                           scrnseg_.
  20218.  
  20219.  
  20220.          SCREEN_WRITE_METHOD - Returns 1 if writing directly to the
  20221.                                screen, 0 if using the BIOS.  You can
  20222.                                also use this macro to assign the
  20223.                                particular writing method.  This macro
  20224.  
  20225.  
  20226.  
  20227.          Page 323          The C Window Library               Page 323
  20228.  
  20229.                                controls the way The C Window Library
  20230.                                will do screen updates.  The default is
  20231.                                1 (write directly to screen).
  20232.  
  20233.                                Example:
  20234.                                #include "vidsys.h"
  20235.                                int a,b;
  20236.                                a =  SCREEN_WRITE_METHOD;
  20237.                                SCREEN_WRITE_METHOD = 1;
  20238.  
  20239.             This macro is a pseudonym for the variable scrnwrt_flag
  20240.             which is a member of the SYS_FLAGS structure
  20241.             video_system_flags.
  20242.  
  20243.  
  20244.          VIDEO_PAGESIZE - Returns the size (in bytes) of a video page.
  20245.                           You can also assign values to
  20246.                           VIDEO_PAGESIZE, but the best thing to do is
  20247.                           to leave it alone unless you are familiar
  20248.                           with the video system you are using.  This
  20249.                           macro is a pseudonym for the variable
  20250.                           pagesize_.
  20251.  
  20252.                          Example:
  20253.                          #include "vidsys.h"
  20254.                          int psize;
  20255.                          psize = VIDEO_PAGESIZE; /* Return the current
  20256.                                                     video page size */
  20257.  
  20258.          The following macros are used to identify the monitor type
  20259.          and video card being used in the system.  Note :  These
  20260.          macros are pseudonyms for members in the SYS_FLAGS structure
  20261.                  called video_system_flags.
  20262.  
  20263.  
  20264.           CGA_ACTIVE    -   Returns 1 if Color Graphics Adapter is
  20265.                             active, 0 otherwise.
  20266.  
  20267.           EGA_ACTIVE    -   Returns 1 if EGA is active, 0 otherwise.
  20268.  
  20269.           EGA_COLOR_ATTACHED - Returns 1 if monitor hooked up to EGA
  20270.                                is a high resolution color monitor, 0
  20271.                                otherwise.
  20272.  
  20273.           EGA_COLOR_ON  - Returns 1 if EGA is in color mode, 0
  20274.                           otherwise.
  20275.  
  20276.           EGA_INSTALLED - Returns 1 if EGA is installed, 0 otherwise.
  20277.  
  20278.           HERCULES_ACTIVE - Returns 1 if Hercules adapter is active, 0
  20279.                             otherwise.
  20280.  
  20281.           MCGA_ACTIVE    - Returns 1 if the MCGA is the active video
  20282.                            card.
  20283.  
  20284.  
  20285.  
  20286.  
  20287.          Page 324          The C Window Library               Page 324
  20288.  
  20289.           MCGA_COLOR_ON - Returns 1 if MCGA is in color mode, 0
  20290.                           otherwise.
  20291.  
  20292.           MCGA_INSTALLED - Returns 1 if MCGA is installed (IBM PS/2
  20293.                            Model 30), 0 otherwise.
  20294.  
  20295.           MDA_ACTIVE    -   Returns 1 if MDA (Monochrome) adapter is
  20296.                             active, 0 otherwise.
  20297.  
  20298.           MONO_MODE_ON  -   Returns 1 if Monochrome mode is on
  20299.                             regardless of the adapter, 0 otherwise.
  20300.  
  20301.           VGA_ACTIVE    -   Returns 1 if VGA is active adapter, 0
  20302.                             otherwise.
  20303.  
  20304.           VGA_COLOR_ATTACHED - Returns 1 if monitor hooked up to VGA
  20305.                                is analog color, 0 otherwise.
  20306.  
  20307.           VGA_COLOR_ON  -   Returns 1 if VGA is in color mode, 0
  20308.                             otherwise.
  20309.  
  20310.           VGA_INSTALLED -   Returns 1 if VGA Adapter is installed, 0
  20311.                             otherwise.
  20312.  
  20313.  
  20314.           You should always check the ..._ACTIVE constants before
  20315.           checking for other aspects of the video system.  For
  20316.           example, make sure that VGA_ACTIVE returns 1 before checking
  20317.           any other VGA_... macro.  If VGA_ACTIVE is 1, then all
  20318.           VGA_... macros are valid.  The same thing goes for EGA.
  20319.           MONO_MODE_ON is the only macro that can be tested regardless
  20320.           of the video adapter.
  20321.  
  20322.           The following are macros defined in version 1.0 of The C
  20323.           Window Library, which are still supported:
  20324.  
  20325.           CGA_MODE_ON  - Same as CGA_ACTIVE.
  20326.           EGA_MODE_ON  - Same as EGA_ACTIVE.
  20327.           VGA_MODE_ON  - Same as VGA_ACTIVE.
  20328.           MCGA_MODE_ON - Same as MCGA_ACTIVE.
  20329.           EGA_MONO_ON  - Returns 1 if EGA is in mono mode.
  20330.           VGA_MONO_ON  - Returns 1 if VGA is in mono mode.
  20331.           MCGA_MONO_ON - Returns 1 if MCGA is in mono mode.
  20332.  
  20333.           You should not assign values to the above pseudo-constants
  20334.           unless you are completely familiar with The C Window
  20335.           Library's internal functions.
  20336.  
  20337.           LINEMODE25 - Returns 1 if screen displays 25 lines, 0
  20338.                        otherwise.
  20339.  
  20340.           LINEMODE43 - Returns 1 if screen displays 43
  20341.                        lines (EGA and VGA), 0 otherwise.
  20342.  
  20343.           LINEMODE50 - Returns 1 if screen displays 50 lines (VGA), 0
  20344.                        otherwise.
  20345.  
  20346.  
  20347.          Page 325          The C Window Library               Page 325
  20348.  
  20349.                              BOX MACROS
  20350.                              ----------
  20351.  
  20352.  
  20353.           The list of defined box drawing macros is as follows:
  20354.  
  20355.                               DOUBLEBOX
  20356.                               SINGLEBOX
  20357.                               MIXEDBOX1
  20358.                               MIXEDBOX2
  20359.                               HATCHBOX1
  20360.                               HATCHBOX2
  20361.                               HATCHBOX3
  20362.                               SOLIDBOX1
  20363.                               SOLIDBOX2
  20364.                               BLANKBOX
  20365.                               DOTTEDLINE
  20366.  
  20367.           Each one of these macros are 8 character strings that can be
  20368.           used in functions that call for a string of box drawing
  20369.           characters.
  20370.  
  20371.  
  20372.  
  20373.  
  20374.  
  20375.  
  20376.  
  20377.  
  20378.  
  20379.  
  20380.  
  20381.  
  20382.  
  20383.  
  20384.  
  20385.  
  20386.  
  20387.  
  20388.  
  20389.  
  20390.  
  20391.  
  20392.  
  20393.  
  20394.  
  20395.  
  20396.  
  20397.  
  20398.  
  20399.  
  20400.  
  20401.  
  20402.  
  20403.  
  20404.  
  20405.  
  20406.  
  20407.          Page 326          The C Window Library               Page 326
  20408.  
  20409.                           EXPLOSION MACROS
  20410.                           ----------------
  20411.  
  20412.           The list of explosion constants is as follows:
  20413.  
  20414.                               NOEFFECT
  20415.                               EXPLODE
  20416.                               CONTRACT
  20417.                               BRICKS
  20418.                               MIDDLEROWOUT
  20419.                               TOPBOTTOMIN
  20420.                               TOPDOWN
  20421.                               BOTTOMUP
  20422.                               MIDDLECOLOUT
  20423.                               LEFTRIGHTIN
  20424.                               LEFTTORIGHT
  20425.                               RIGHTTOLEFT
  20426.  
  20427.  
  20428.  
  20429.  
  20430.  
  20431.  
  20432.  
  20433.  
  20434.  
  20435.  
  20436.  
  20437.  
  20438.  
  20439.  
  20440.  
  20441.  
  20442.  
  20443.  
  20444.  
  20445.  
  20446.  
  20447.  
  20448.  
  20449.  
  20450.  
  20451.  
  20452.  
  20453.  
  20454.  
  20455.  
  20456.  
  20457.  
  20458.  
  20459.  
  20460.  
  20461.  
  20462.  
  20463.  
  20464.  
  20465.  
  20466.  
  20467.          Page 327          The C Window Library               Page 327
  20468.  
  20469.                            KEYBOARD MACROS
  20470.                            ---------------
  20471.  
  20472.          The following macros are used to get characters from the
  20473.          keyboard.  They are prototyped in the file key.h.
  20474.  
  20475.  
  20476.          ENHANCED_KEYBOARD() - Returns 1 if there is an enhanced
  20477.                                keyboard attached, 0 otherwise.
  20478.  
  20479.          FLUSH_KEYBOARD() - Flushes the keyboard buffer.
  20480.  
  20481.          GET_KEY() - Returns what key was pressed either as a
  20482.                      character, or as a scan code if a non-ascii key
  20483.                      is pressed.  A list of scan codes are found in
  20484.                      the file keycodes.h.
  20485.  
  20486.          GET_ENHANCED_KEY() - Same as GET_KEY() except that keys on
  20487.                               the enhanced keyboards are
  20488.                               distinguishable.  For instance, the  key
  20489.                               on the keypad will return a different
  20490.                               scan code than the Home key on the
  20491.                               separate cursor movement pad.
  20492.  
  20493.          GET_SHIFT_STATE() - Returns the shift state of the keyboard.
  20494.                              The shift state tells whether the Alt,
  20495.                              Ctrl or Shift key was pressed, or if the
  20496.                              Num Lock, Scroll Lock, or Caps Lock keys
  20497.                              are on or off.  The shift state is
  20498.                              updated after each call to GET_KEY() or
  20499.                              GET_ENHANCED_KEY().  Use a bitwise AND
  20500.                              (&) when testing for these keys.
  20501.                              The #defined constants that are used to
  20502.                              test for the various keys is found in
  20503.                              keycodes.h.
  20504.  
  20505.                     Example:
  20506.  
  20507.                     #include "key.h"
  20508.                     #include "keycodes.h"
  20509.                     #include <stdio.h>
  20510.  
  20511.                     main()
  20512.                     {
  20513.                       int CurrentShift;
  20514.                       GET_KEY();
  20515.  
  20516.                       /* both ALT and CTRL must be pressed */
  20517.                       CurrentShift = (GET_SHIFT_STATE() & ALT) &&
  20518.                                      (GET_SHIFT_STATE() & CTRL);
  20519.  
  20520.                       printf("The Ctrl and Alt key was %s pressed",
  20521.                               CurrentShift?"":"not");
  20522.                     }
  20523.  
  20524.  
  20525.  
  20526.  
  20527.          Page 328          The C Window Library               Page 328
  20528.  
  20529.          ISKEYREADY() - Returns 1 if there is a key ready in the
  20530.                          keyboard buffer, 0 otherwise.
  20531.  
  20532.  
  20533.          Keyboard Idle function
  20534.          ----------------------
  20535.  
  20536.          When calling the GET_KEY() or GET_ENHANCED_KEY() macros, you
  20537.          can call a function while the program is waiting for a key to
  20538.          be pressed.  The global variable key_idle_func is a function
  20539.          pointer that points to this function.  Here is the prototype:
  20540.  
  20541.                        void (*key_idle_func)(void)
  20542.  
  20543.          There are no arguments and no return value to this function.
  20544.          You must initialize this function pointer after you have
  20545.          called WindowInitializeSystem().  If not, the function you
  20546.          assigned will not be executed.  Here is an example:
  20547.  
  20548.  
  20549.          #include "window.h"
  20550.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  20551.          void count_numbers(void);
  20552.          int num = 0;
  20553.  
  20554.          main()
  20555.          {
  20556.            WindowInitializeSystem();
  20557.            key_idle_func = count_numbers;
  20558.            ClearScreen(NORM);
  20559.            GET_KEY();
  20560.            MoveCursor(2,1,0);
  20561.            VideoPrintf("You stopped the count at %d",num);
  20562.          }
  20563.  
  20564.          void count_numbers()
  20565.          {
  20566.            num++;
  20567.            MoveCursor(1,1,0);
  20568.            VideoPrintf("%d",num);
  20569.            delay(1000);
  20570.          }
  20571.  
  20572.  
  20573.          The program above keeps a counter going in the upper left
  20574.          hand corner of the screen until a key is pressed.
  20575.  
  20576.          If you want to unassign the key_idle_func function pointer,
  20577.          do the following:
  20578.  
  20579.                       key_idle_func = VOIDNULLFN;
  20580.  
  20581.          This function can perform just about anything.  One major use
  20582.          would be to update an on-screen clock while the keyboard is
  20583.          not being used.
  20584.  
  20585.  
  20586.  
  20587.          Page 329          The C Window Library               Page 329
  20588.  
  20589.          Keyboard Intercept function
  20590.          ---------------------------
  20591.  
  20592.          Before GET_KEY() and GET_ENHANCED_KEY() return a value, you
  20593.          can intercept the pending return value, examine it, and
  20594.          change the value to whatever you wish.  This is good if you
  20595.          want to reassign keys easily.  The function pointer to assign
  20596.          is key_intercept_func.  Here is the prototype:
  20597.  
  20598.            unsigned (*key_intercept_func)(int which, unsigned keyval)
  20599.  
  20600.          The first argument is an integer that denotes whether a mouse
  20601.          button was pressed, or a key from the keyboard was pressed.
  20602.          If a keyboard key was pressed, the value of which is equal to
  20603.          KEYPRESSED, otherwise it is MOUSEPRESSED.  If you do not have
  20604.          a mouse, or the mouse is not activated, this value will
  20605.          always be KEYPRESSED.  More information on the mouse in the
  20606.          USING THE MOUSE section in the manual.  The return value will
  20607.          be the new key value that GET_KEY() and GET_ENHANCED_KEY()
  20608.          will return.  It is advisable to use the key codes described
  20609.          in "keycodes.h" if you are returning a non-ascii key.  Here
  20610.          is an example:
  20611.  
  20612.          #include "window.h"
  20613.          #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  20614.          unsigned switch_to_quotes(int,unsigned);
  20615.          unsigned oldchar;
  20616.  
  20617.          main()
  20618.          {
  20619.            int ch;
  20620.            WindowInitializeSystem();
  20621.            key_intercept_func = switch_to_quotes;
  20622.            ClearScreen(NORM);
  20623.            ch = GET_KEY();
  20624.            MoveCursor(1,1,0);
  20625.            VideoPrintf(
  20626.               "The old key was %c.  The new code is %c",oldchar,ch);
  20627.          }
  20628.  
  20629.          unsigned switch_to_quotes(int which, unsigned keyval)
  20630.          {
  20631.            if (which == KEYPRESSED)
  20632.            {
  20633.              oldchar = keyval;
  20634.              return (unsigned)'"';  /* return a double quote */
  20635.            }
  20636.          }
  20637.  
  20638.  
  20639.  
  20640.  
  20641.  
  20642.  
  20643.  
  20644.  
  20645.  
  20646.  
  20647.          Page 330          The C Window Library               Page 330
  20648.  
  20649.          The program above intercepts the return value of GET_KEY()
  20650.          and assigns the double quote character.  The character is
  20651.          then printed out on the screen along with the character that
  20652.          was assigned.
  20653.  
  20654.          If you want to unassign the key_intercept_func function
  20655.          pointer, do the following:
  20656.  
  20657.                   key_intercept_func = NULLFN;
  20658.  
  20659.  
  20660.  
  20661.  
  20662.          Checking for mouse button presses
  20663.          ---------------------------------
  20664.  
  20665.          The GET_MPRESS_KEY() and GET_MPRESS_ENHANCED_KEY() macros
  20666.          work the same as the GET_KEY() and GET_ENHANCED_KEY()
  20667.          macros, which are described below and used in some previous
  20668.          examples, except that GET_MPRESS_KEY() and
  20669.          GET_MPRESS_ENHANCED_KEY() also test to see if one or more
  20670.          mouse buttons has been pressed.
  20671.  
  20672.          When GET_MPRESS_KEY() or GET_MPRESS_ENHANCED_KEY() is
  20673.          called, the program is suspended until a key on the keyboard
  20674.          is pressed, or one or more mouse buttons has been pressed.
  20675.          The difference between these two macros is that
  20676.          GET_MPRESS_ENHANCED_KEY() recognizes keys on an enhanced
  20677.          (101 key) keyboard.  Here is a prototype for both of these
  20678.          macros:
  20679.  
  20680.            unsigned int GET_MPRESS_KEY(int *which)
  20681.  
  20682.            unsigned int GET_MPRESS_ENHANCED_KEY(int *which)
  20683.  
  20684.          The only argument is a pointer to an integer which will
  20685.          contain either MOUSEPRESSED if the mouse was pressed, or
  20686.          KEYBOARDPRESSED if a key on the keyboard was pressed.  The
  20687.          kyboard_idle_func and keyboard_intercept_func function
  20688.          pointers are fully implemented when either of these macros
  20689.          are called.
  20690.  
  20691.          Both of these macros return either the key that was struck,
  20692.          or the mouse button(s) that was(were) pressed.  The values
  20693.          for these mouse buttons are as follows:
  20694.  
  20695.  
  20696.          MOUSELEFT_PRESS   - Left button was pressed.
  20697.  
  20698.          MOUSERIGHT_PRESS  - Right button was pressed.
  20699.  
  20700.          MOUSEMIDDLE_PRESS - Middle button was pressed.
  20701.  
  20702.          MOUSELEFTRIGHT_PRESS  - Left and Right was pressed
  20703.                                  simultaneously.
  20704.  
  20705.  
  20706.  
  20707.          Page 331          The C Window Library               Page 331
  20708.  
  20709.          MOUSEMIDDLERIGHT_PRESS - Middle and Right buttons were
  20710.                                   pressed simultaneously.
  20711.  
  20712.          MOUSEMIDDLELEFT_PRESS  - Middle and Left buttons pressed
  20713.                                   simultaneously.
  20714.  
  20715.          MOUSEMIDDLERIGHTLEFT_PRESS - Middle, right, and left buttons
  20716.                                       pressed simultaneously.
  20717.  
  20718.          If a keyboard key is hit, the return values are the same as
  20719.          for GET_KEY() or GET_ENHANCED_KEY().
  20720.  
  20721.          Example:
  20722.  
  20723.          #include "cwlmouse.h"
  20724.          #include "window.h"
  20725.          #define NORM  CREATE_VIDEO_ATTRIBUTE(BLACK_,WHITE_)
  20726.  
  20727.          void print_nums();
  20728.  
  20729.          main()
  20730.          {
  20731.            int w,b;
  20732.            unsigned ch;
  20733.            WindowInitializeSystem();
  20734.            ClearScreen(NORM);
  20735.            MouseInitializeSystem(MOUSE_FULL_INSTALL,&b,10,10);
  20736.            key_idle_func = print_nums;
  20737.            ch = GET_MPRESS_KEY(&w);
  20738.            VideoPrintf("\nThe %s was pressed.  Value is %d",
  20739.                         (w==MOUSEPRESSED?"Mouse":"Keyboard"),ch);
  20740.            MouseRestoreSystem();
  20741.          }
  20742.  
  20743.          void print_nums()
  20744.          {
  20745.            static int count = 0;
  20746.            MoveCursor(1,1,0);
  20747.            VideoPrintf("%d",count++);
  20748.          }
  20749.  
  20750.  
  20751.  
  20752.  
  20753.  
  20754.  
  20755.  
  20756.  
  20757.  
  20758.  
  20759.  
  20760.  
  20761.  
  20762.  
  20763.  
  20764.  
  20765.  
  20766.  
  20767.          Page 332          The C Window Library               Page 332
  20768.  
  20769.                             CURSOR MACROS
  20770.                             -------------
  20771.  
  20772.  
  20773.          The following macros are used for cursor manipulation.
  20774.  
  20775.  
  20776.          CREATE_CURSOR_SHAPE(startline, endline) - Forms an integer
  20777.                              quantity representing a cursor with a
  20778.                              starting scan line of scanline, and an
  20779.                              ending scan line of endline.
  20780.  
  20781.          THIN - constant for a thin (underline) cursor.
  20782.  
  20783.          BLOCK - constant for a block (fat) cursor.
  20784.  
  20785.          INVISIBLE - constant for a hidden cursor.
  20786.  
  20787.  
  20788.  
  20789.  
  20790.  
  20791.  
  20792.  
  20793.  
  20794.  
  20795.  
  20796.  
  20797.  
  20798.  
  20799.  
  20800.  
  20801.  
  20802.  
  20803.  
  20804.  
  20805.  
  20806.  
  20807.  
  20808.  
  20809.  
  20810.  
  20811.  
  20812.  
  20813.  
  20814.  
  20815.  
  20816.  
  20817.  
  20818.  
  20819.  
  20820.  
  20821.  
  20822.  
  20823.  
  20824.  
  20825.  
  20826.  
  20827.          Page 333          The C Window Library               Page 333
  20828.  
  20829.                      IMPORTANT GLOBAL VARIABLES
  20830.                      --------------------------
  20831.  
  20832.          There are global variables that you should be aware of in The
  20833.          C Window Library.  Most of these variables can be changed,
  20834.          while others should be left alone.  You must call
  20835.          WindowInitializeSystem() before modifying any of these
  20836.          variables.
  20837.  
  20838.          When describing the global variable, the following scheme is
  20839.          used:
  20840.  
  20841.  
  20842.  
  20843.  
  20844.  
  20845.          Variable         variable name
  20846.  
  20847.          Defined in       XXXXXX.h  (file where variable is declared)
  20848.  
  20849.          Initialized in   function call (function where variable gets
  20850.                                          its initial value)
  20851.  
  20852.          Purpose          Description of variable's purpose.
  20853.  
  20854.          Default Value    default value for variable.
  20855.  
  20856.          Modify Info      Tells if variable should be modified.
  20857.  
  20858.  
  20859.  
  20860.          These variables are described in alphabetical order.
  20861.  
  20862.  
  20863.  
  20864.  
  20865.  
  20866.  
  20867.  
  20868.          Variable         int active_video_page
  20869.  
  20870.          Defined in       vidsys.h
  20871.  
  20872.          Initialized in   WindowInitializeSystem()
  20873.  
  20874.          Purpose          Current active video page.
  20875.  
  20876.          Modify Info      Should be modified only by calling the
  20877.                           SetActiveVideoPage() function.
  20878.  
  20879.  
  20880.  
  20881.  
  20882.  
  20883.  
  20884.  
  20885.  
  20886.  
  20887.          Page 334          The C Window Library               Page 334
  20888.  
  20889.          Variable         int barmenu_button_press
  20890.  
  20891.          Defined in       cwlmouse.h
  20892.  
  20893.          Initialized in   MouseInitializeSystem()
  20894.  
  20895.          Purpose          Holds the current button mouse button to
  20896.                           press to move the highlight bar on bar
  20897.                           menus.
  20898.  
  20899.          Default Value    MOUSELEFT_PRESS.
  20900.  
  20901.          Modify Info      Can be modified at any time.
  20902.  
  20903.  
  20904.  
  20905.  
  20906.  
  20907.          Variable         int caldelay_
  20908.  
  20909.          Defined          vidsys.h
  20910.  
  20911.          Initialized in   WindowInitializeSystem()
  20912.  
  20913.          Purpose          This is a calibration count for the delay()
  20914.                           function.
  20915.  
  20916.          Modify Info      Should only be modified if the delay()
  20917.                           function is giving inaccurate delay times.
  20918.                           If the delay is too long, then caldelay_
  20919.                           should be decreased.  If it is too short,
  20920.                           then caldelay_ should be increased.
  20921.  
  20922.  
  20923.  
  20924.  
  20925.          Variable         int check_existence_flag
  20926.  
  20927.          Defined in       window.h
  20928.  
  20929.          Initialized in   WindowInitializeSystem()
  20930.  
  20931.          Purpose          Informs The C Window Library to check for
  20932.                           window, virtual window, and for non-open
  20933.                           window errors.  If this variable is 1, the
  20934.                           library routines will check for these
  20935.                           conditions.  If 0, these conditions are not
  20936.                           checked.
  20937.  
  20938.          Default Value    1.
  20939.  
  20940.          Modify Info      Can be modified at any time, but is
  20941.                           recommended that this flag be left on for
  20942.                           development work.  Make sure that your
  20943.                           application program is stable if you plan to
  20944.                           turn off checking.
  20945.  
  20946.  
  20947.          Page 335          The C Window Library               Page 335
  20948.  
  20949.          Variable         int chksnow_
  20950.  
  20951.          Defined          vidsys.h
  20952.  
  20953.          Initialized in   WindowInitializeSystem()
  20954.  
  20955.          Purpose          This variable controls whether the display
  20956.                           should be checked for snow when writing
  20957.                           directly to the screen.  A value of 1 will
  20958.                           check for snow, while a value of 0 will turn
  20959.                           off snow checking.
  20960.  
  20961.          Default Value    0 (no snow checking).
  20962.  
  20963.          Modify Info      Can be modified at any time.
  20964.  
  20965.  
  20966.  
  20967.  
  20968.  
  20969.          Variable         int crt_status_port
  20970.  
  20971.          Defined          vidsys.h
  20972.  
  20973.          Initialized in   WindowInitializeSystem()
  20974.  
  20975.          Purpose          This variable holds the value of the CRT
  20976.                           status port.  This port is used to test when
  20977.                           it is safe to read or write characters to
  20978.                           the screen without producing snow.
  20979.  
  20980.          Modify Info      Should not be modified.
  20981.  
  20982.  
  20983.  
  20984.  
  20985.          Variable         int default_cursor_mode
  20986.  
  20987.          Defined          key.h
  20988.  
  20989.          Initialized in   WindowInitializeSystem()
  20990.  
  20991.          Purpose          Holds the mode that the WindowGet...()
  20992.                           functions will operate in when called.  The
  20993.                           modes are either OVERSTRIKEMODE or
  20994.                           INSERTMODE.
  20995.  
  20996.          Default Value    OVERSTRIKEMODE.
  20997.  
  20998.          Modify Info      Can be modified at any time.
  20999.  
  21000.                           Example:
  21001.  
  21002.                           default_cursor_mode = INSERTMODE;
  21003.  
  21004.  
  21005.  
  21006.  
  21007.          Page 336          The C Window Library               Page 336
  21008.  
  21009.          Variable         int default_cursor_type[2]
  21010.  
  21011.          Defined          key.h
  21012.  
  21013.          Initialized in   WindowInitializeSystem()
  21014.  
  21015.          Purpose          Holds the cursor shapes for OVERSTRIKEMODE
  21016.                           and INSERTMODE input modes.
  21017.  
  21018.          Default Value    default_cursor_type[OVERSTRIKEMODE] is set
  21019.                           to a block cursor.
  21020.                           default_cursor_type[INSERTMODE] is set to an
  21021.                           underline cursor.
  21022.  
  21023.          Modify Info      Can be modified at any time.
  21024.  
  21025.                           Example:
  21026.  
  21027.                           default_cursor_type[INSERTMODE] =
  21028.                                         CREATE_CURSOR_SHAPE(5,7);
  21029.  
  21030.  
  21031.  
  21032.  
  21033.  
  21034.          Variable         int default_screen_attr
  21035.  
  21036.          Defined in       vidsys.h
  21037.  
  21038.          Initialized in   WindowInitializeSystem()
  21039.  
  21040.          Purpose          Default video attribute used when any
  21041.                           Video...() functions are called to write to
  21042.                           the screen.
  21043.  
  21044.          Default Value    7 (black background, white foreground).
  21045.  
  21046.          Modify Info      Can be modified at any time.
  21047.  
  21048.  
  21049.  
  21050.  
  21051.  
  21052.          Variable         int enhanced_keyboard
  21053.  
  21054.          Defined in       key.h
  21055.  
  21056.          Initialized in   WindowInitializeSystem()
  21057.  
  21058.          Purpose          Tells if an enhanced keyboard is attached.
  21059.                           If enhanced_keyboard is 1, an enhanced
  21060.                           keyboard is active, otherwise if 0, the
  21061.                           keyboard is not an enhanced keyboard.
  21062.  
  21063.          Modify Info      Can be modified safely.
  21064.  
  21065.  
  21066.  
  21067.          Page 337          The C Window Library               Page 337
  21068.  
  21069.          Variable         int explosion_speed[12]
  21070.  
  21071.          Defined in       window.h
  21072.  
  21073.          Initialized in   WindowInitializeSystem()
  21074.  
  21075.          Purpose          This array holds the number of milliseconds
  21076.                           of delay for each of the special effects
  21077.                           supported in The C Window Library.
  21078.  
  21079.          Default Value    10 (10 ms.), except for
  21080.                           explosion_speed[BRICKS], which is 1 ms.
  21081.  
  21082.          Modify Info      Can be modified safely at anytime.  The way
  21083.                           you would modify the values is to use the
  21084.                           special effects constants.  For example:
  21085.  
  21086.                                explosion_speed[CONTRACT] = 5;
  21087.  
  21088.                           The above example changes the explosion
  21089.                           delay for the CONTRACT special effect to 5
  21090.                           ms.
  21091.  
  21092.  
  21093.  
  21094.  
  21095.  
  21096.          Variable         int flush_keyboard_flag.
  21097.  
  21098.          Defined in       key.h
  21099.  
  21100.          Initialized in   WindowInitializeSystem().
  21101.  
  21102.          Purpose          Tells if the keyboard buffer should be
  21103.                           flushed whenever the GET_KEY() or
  21104.                           GET_ENHANCED_KEY() macros are called.  A
  21105.                           value of 1 means the buffer will be flushed.
  21106.  
  21107.          Default Value    0 (no flush).
  21108.  
  21109.          Modify Info      Can be modified at any time.
  21110.  
  21111.  
  21112.  
  21113.  
  21114.  
  21115.  
  21116.  
  21117.  
  21118.  
  21119.  
  21120.  
  21121.  
  21122.  
  21123.  
  21124.  
  21125.  
  21126.  
  21127.          Page 338          The C Window Library               Page 338
  21128.  
  21129.          Variable         VIDEO_CONFIG initial_video_startup
  21130.  
  21131.          Defined in       vidsys.h
  21132.  
  21133.          Initialized in   WindowInitializeSystem()
  21134.  
  21135.          Purpose          Structure that holds the video configuration
  21136.                           when WindowInitializeSystem() is called.
  21137.  
  21138.          Modify info      Should not be modified if the initial video
  21139.                           startup is desired when exiting an
  21140.                           application.
  21141.  
  21142.  
  21143.  
  21144.  
  21145.  
  21146.  
  21147.          Variable         char input_mask_char
  21148.  
  21149.          Defined in       window.h
  21150.  
  21151.          Initialized in   WindowInitializeSystem()
  21152.  
  21153.          Purpose          Holds the mask character that is used for
  21154.                           input routines.  The character defined in
  21155.                           input_mask_char is used in input masks to
  21156.                           specify an input position in the edit field.
  21157.                           Refer to the functions WindowGet..()
  21158.                           functions for more information concerning
  21159.                           character masks.
  21160.  
  21161.          Default Value    '_'  (0x5F).
  21162.  
  21163.          Modify Info      Can be modified safely at any time, except
  21164.                           when in the middle of a user defined
  21165.                           function that was called by The C Window
  21166.                           Library's input routines.
  21167.  
  21168.  
  21169.  
  21170.  
  21171.  
  21172.          Variable         void (*key_idle_func)(void)
  21173.  
  21174.          Defined in       key.h
  21175.  
  21176.          Initialized in   WindowInitializeSystem()
  21177.  
  21178.          Purpose          pointer that points to a function that is
  21179.                           performed whenever the GET_KEY() and
  21180.                           GET_ENHANCED_KEY() macros do not have a key
  21181.                           ready to be processed.
  21182.  
  21183.          Modify Info      Can be modified at any time.
  21184.  
  21185.  
  21186.  
  21187.          Page 339          The C Window Library               Page 339
  21188.  
  21189.          Variable         unsigned (*key_intercept_func)(int which,
  21190.                                                        unsigned keyval)
  21191.  
  21192.          Defined in       key.h
  21193.  
  21194.          Initialized in   WindowInitializeSystem()
  21195.  
  21196.          Purpose          pointer that points to a function which
  21197.                           traps any keystrokes that the GET_KEY() and
  21198.                           GET_ENHANCED_KEY() macros will return.
  21199.  
  21200.          Modify Info      Can be modified at any time.
  21201.  
  21202.  
  21203.  
  21204.  
  21205.  
  21206.  
  21207.          Variable         int max_video_pages
  21208.  
  21209.          Defined in       vidsys.h
  21210.  
  21211.          Initialized in   WindowInitializeSystem()
  21212.  
  21213.          Purpose          Total number of video pages detected by The
  21214.                           C Window Library.
  21215.  
  21216.          Modify Info      Should not be modified unless a modification
  21217.                           to the screen_page_offset array was done.
  21218.  
  21219.  
  21220.  
  21221.  
  21222.  
  21223.          Variable         int max_window_rank
  21224.  
  21225.          Defined in       window.h
  21226.  
  21227.          Initialized in   WindowInitializeSystem()
  21228.  
  21229.          Purpose          Holds the rank value of the bottom-most
  21230.                           (i.e. the window that will have all other
  21231.                           windows covering it).
  21232.  
  21233.          Modify Info      Do not modify.
  21234.  
  21235.  
  21236.  
  21237.  
  21238.  
  21239.  
  21240.  
  21241.  
  21242.  
  21243.  
  21244.  
  21245.  
  21246.  
  21247.          Page 340          The C Window Library               Page 340
  21248.  
  21249.          Variable         int min_window_rank
  21250.  
  21251.          Defined in       window.h
  21252.  
  21253.          Initialized in   WindowInitializeSystem()
  21254.  
  21255.          Purpose          Holds the rank value of the top-most visible
  21256.                           window.
  21257.  
  21258.          Modify Info      Do not modify.
  21259.  
  21260.  
  21261.  
  21262.  
  21263.  
  21264.  
  21265.          Variable         int (*num_chars_entered_func)(char *string,
  21266.                                                         int minchars)
  21267.  
  21268.          Defined in       key.h
  21269.  
  21270.          Arguments        string - string that was entered.
  21271.  
  21272.                           minchars - minimum number of characters
  21273.                           expected.
  21274.  
  21275.          Initialized in   WindowInitializeSystem()
  21276.  
  21277.          Purpose          Pointer to user-defined function that will
  21278.                           be executed when the input manager detects
  21279.                           that there were not enough characters
  21280.                           entered.
  21281.  
  21282.          Default Value    NULLFN.
  21283.  
  21284.  
  21285.  
  21286.  
  21287.  
  21288.          Variable         int num_transparent_shadows[16]
  21289.  
  21290.          Defined in       window.h
  21291.  
  21292.          Initialized in   WindowInitializeSystem()
  21293.  
  21294.          Purpose          Array of the number of transparent shadows
  21295.                           that are currently displayed for each
  21296.                           display page.
  21297.  
  21298.          Default Value    0 for each array element.
  21299.  
  21300.          Modify Info      Do not modify.
  21301.  
  21302.  
  21303.  
  21304.  
  21305.  
  21306.  
  21307.          Page 341          The C Window Library               Page 341
  21308.  
  21309.          Variable         WPOINTER orig_screen[16]
  21310.  
  21311.          Defined in       window.h
  21312.  
  21313.          Initialized in   WindowSaveInitial()
  21314.  
  21315.          Purpose          Array of windows created when
  21316.                           WindowSaveInitial() is called.  The original
  21317.                           screen for video page 0 is orig_screen[0],
  21318.                           page 1 is orig_screen[1], etc.  Modify Info
  21319.                           You can use any window function on the
  21320.                           original screen, except for ones that
  21321.                           resize, move, hide, display, or close.  If
  21322.                           you write strings to the original screen,
  21323.                           you will permanently destroy the contents of
  21324.                           the original screen at the positions that
  21325.                           have been modified.
  21326.  
  21327.                           Example:
  21328.  
  21329.                           WindowWriteString(orig_screen[0],"123",1,1);
  21330.  
  21331.                           The above example writes "123" to the upper
  21332.                           left hand corner of the original screen of
  21333.                           video page 0.
  21334.  
  21335.  
  21336.  
  21337.  
  21338.  
  21339.          Variable         int pagesize_
  21340.  
  21341.          Defined in       window.h
  21342.  
  21343.          Initialized in   WindowInitializeSystem()
  21344.  
  21345.          Purpose          Holds the size of a display page in bytes.
  21346.  
  21347.          Modify Info      Should not be modified unless The C Window
  21348.                           Library did not detect the correct video
  21349.                           page size.
  21350.  
  21351.  
  21352.  
  21353.  
  21354.  
  21355.  
  21356.  
  21357.  
  21358.  
  21359.  
  21360.  
  21361.  
  21362.  
  21363.  
  21364.  
  21365.  
  21366.  
  21367.          Page 342          The C Window Library               Page 342
  21368.  
  21369.          Variable         int popmenu_button_press
  21370.  
  21371.          Defined in       cwlmouse.h
  21372.  
  21373.          Initialized in   MouseInitializeSystem()
  21374.  
  21375.          Purpose          Holds the current button mouse button to
  21376.                           press to move the highlight bar on popup
  21377.                           menus.
  21378.  
  21379.          Default Value    MOUSELEFT_PRESS.
  21380.  
  21381.          Modify Info      Can be modified at any time.
  21382.  
  21383.  
  21384.  
  21385.  
  21386.  
  21387.          Variable         int (*reg_exp_error_func)(char *string,
  21388.                                                      int nomatch)
  21389.  
  21390.          Defined in       key.h
  21391.  
  21392.          Arguments        string - string that was entered.
  21393.  
  21394.                           nomatch - position of the first non-matching
  21395.                           character.
  21396.  
  21397.          Initialized in   WindowInitializeSystem()
  21398.  
  21399.          Purpose          Pointer to user-defined function that will
  21400.                           be executed when the input manager detects
  21401.                           that there are illegal characters in the
  21402.                           string when it is compared to the regular
  21403.                           expression.  This function is only called
  21404.                           when it is not equal to NULLFN, and the
  21405.                           CHECKREGEXP option is on.
  21406.  
  21407.          Default Value    NULLFN.
  21408.  
  21409.          Modify info      Can be modified at any time.
  21410.  
  21411.          Return Values    Must return DONT_PROCESS or ACCEPT_INPUT.
  21412.  
  21413.  
  21414.  
  21415.  
  21416.  
  21417.          Variable         unsigned char *screen_image[16]
  21418.  
  21419.          Defined in       window.h
  21420.  
  21421.          Initialized in   WindowInitializeSystem()
  21422.  
  21423.          Purpose          Used for internal window management.  Each
  21424.  
  21425.  
  21426.  
  21427.          Page 343          The C Window Library               Page 343
  21428.  
  21429.                           pointer in the screen_image array points to
  21430.                           an image of the current window organization
  21431.                           of the screen. For example screen_image[0]
  21432.                           is a pointer to the current window "layout"
  21433.                           for video page 0.
  21434.  
  21435.          Modify Info      DO NOT modify this.  This array is VERY
  21436.                           important when window updates are done.
  21437.  
  21438.  
  21439.  
  21440.  
  21441.  
  21442.          Variable         unsigned char far *screen_page_offset[16]
  21443.  
  21444.          Defined in       window.h
  21445.  
  21446.          Initialized in   WindowInitializeSystem()
  21447.  
  21448.          Purpose          Array of starting addresses of each video
  21449.                           page.
  21450.  
  21451.          Modify Info      You can modify if The C Window Library fails
  21452.                           to detect video pages that your video card
  21453.                           may have.
  21454.  
  21455.                           Invalid video pages will set
  21456.                           screen_page_offset[page] to a far NULL
  21457.                           pointer, where page is the invalid video
  21458.                           page.
  21459.  
  21460.                           If there is a failure to detect video pages
  21461.                           that your card may have, you can use the
  21462.                           MAKE_FAR_POINTER macro to initialize.
  21463.                           Example: screen_page_offset[page] =
  21464.                                    MAKE_FAR_POINTER(0xB000,0x2000);
  21465.  
  21466.                           where page is the page to initialize.  You
  21467.                           should have the documentation of the video
  21468.                           card on hand so that you are sure of the
  21469.                           starting address of the video page.
  21470.  
  21471.                           You must also adjust the global variable
  21472.                           max_video_pages to reflect the new number of
  21473.                           pages, and the pagesize_ variable to reflect
  21474.                           the size of each video page.
  21475.  
  21476.  
  21477.  
  21478.  
  21479.  
  21480.  
  21481.  
  21482.  
  21483.  
  21484.  
  21485.  
  21486.  
  21487.          Page 344          The C Window Library               Page 344
  21488.  
  21489.          Variable         int (*undef_akey_func)(char *string,
  21490.                                                  unsigned key,
  21491.                                                  int pos, int *newpos)
  21492.  
  21493.          Defined in       key.h
  21494.  
  21495.          Arguments        string - string currently entered.
  21496.  
  21497.                           key - key that was hit.
  21498.  
  21499.                           pos - position where cursor is in the input
  21500.                                 string.
  21501.  
  21502.          Purpose          Pointer to a function that is executed when
  21503.                           a key that is not defined in an input
  21504.                           routines regular expression is pressed.
  21505.  
  21506.  
  21507.          Default Value    NULLFN.
  21508.  
  21509.          Modify Info      Can be modified at any time.
  21510.  
  21511.          Return Values    Refer to the manual for more information.
  21512.  
  21513.  
  21514.  
  21515.  
  21516.  
  21517.          Variable         int (*undef_fkey_func)(char *string,
  21518.                                                  unsigned key,
  21519.                                                  int pos, int *newpos)
  21520.  
  21521.          Defined in       key.h
  21522.  
  21523.          Arguments        string - string currently entered.
  21524.  
  21525.                           key - key that was hit.
  21526.  
  21527.                           pos - position where cursor is in the input
  21528.                           string.
  21529.  
  21530.          Purpose          Pointer to a function that is executed when
  21531.                           a key that is not defined in an input
  21532.                           routines regular expression is pressed.
  21533.  
  21534.  
  21535.          Purpose          Pointer to a function that is executed when
  21536.                           a key that is not defined in the
  21537.                           window_edit_key array is pressed.
  21538.  
  21539.          Default Value    NULLFN.
  21540.  
  21541.          Modify Info      Can be modified at any time.
  21542.  
  21543.          Return Values    Refer to to the main documentation for more
  21544.                           information.
  21545.  
  21546.  
  21547.          Page 345          The C Window Library               Page 345
  21548.  
  21549.          Variable         VWPOINTER virtual_window_ptrs[256]
  21550.  
  21551.          Defined in       window.h
  21552.  
  21553.          Purpose          Array of all initialized virtual window
  21554.                           pointers.
  21555.  
  21556.          Modify Info      Do not modify.
  21557.  
  21558.  
  21559.  
  21560.  
  21561.  
  21562.          Variable         int visible_video_page
  21563.  
  21564.          Defined in       vidsys.h
  21565.  
  21566.          Initialized in   WindowInitializeSystem()
  21567.  
  21568.          Purpose          Current visible video page.
  21569.  
  21570.          Modify Info      Should be modified only by calling the
  21571.                           SetVisibleVideoPage() function.
  21572.  
  21573.  
  21574.  
  21575.  
  21576.  
  21577.          Variable         unsigned window_edit_key[12]
  21578.  
  21579.          Defined in       window.h
  21580.  
  21581.          Initialized in   WindowInitializeSystem()
  21582.  
  21583.          Purpose          Array of edit key definitions.  This array
  21584.                           is used in the window input routines.
  21585.  
  21586.          Modify Info      You can modify values in the array, provided
  21587.                           that there are no duplicate definitions, and
  21588.                           there is a definition for a key that
  21589.                           terminates user input.  Refer to the GETTING
  21590.                           INPUT FROM WINDOWS section.
  21591.  
  21592.  
  21593.  
  21594.  
  21595.  
  21596.  
  21597.  
  21598.  
  21599.  
  21600.  
  21601.  
  21602.  
  21603.  
  21604.  
  21605.  
  21606.  
  21607.          Page 346          The C Window Library               Page 346
  21608.  
  21609.          Variable         int window_error_code
  21610.  
  21611.          Defined in       window.h
  21612.  
  21613.          Initialized in   WindowInitializeSystem()
  21614.  
  21615.          Purpose          Holds the last error that occurred as an
  21616.                           integer.  You should always check the value
  21617.                           of window_error_code to determine what has
  21618.                           happened if a function fails.  All of the
  21619.                           window and virtual window functions return
  21620.                           an error status when things go wrong.
  21621.                           However, only selected functions from the
  21622.                           Video...  family of functions set
  21623.                           window_error_code.  The value in
  21624.                           window_error_code corresponds to the values
  21625.                           found in the file werror.h.
  21626.  
  21627.                           window_error_code does not reset itself if
  21628.                           there are no errors.
  21629.  
  21630.          Default Value    0.
  21631.  
  21632.          Modify Info      Safe to modify, but will always reset itself
  21633.                           to an error condition if a function fails.
  21634.  
  21635.  
  21636.  
  21637.  
  21638.  
  21639.          Variable         WPOINTER window_ptrs[256];
  21640.  
  21641.          Defined in       window.h
  21642.  
  21643.          Purpose          Array of all initialized windows.
  21644.  
  21645.          Modify Info      DO NOT modify.
  21646.  
  21647.  
  21648.  
  21649.  
  21650.  
  21651.          Variable         WPOINTER window_rank[257];
  21652.  
  21653.          Defined in       window.h
  21654.  
  21655.          Purpose          Array of all visible windows in rank order.
  21656.  
  21657.          Modify Info      DO NOT modify.
  21658.  
  21659.  
  21660.  
  21661.  
  21662.  
  21663.  
  21664.  
  21665.  
  21666.  
  21667.          Page 347          The C Window Library               Page 347
  21668.  
  21669.  
  21670.  
  21671.  
  21672.  
  21673.  
  21674.  
  21675.  
  21676.  
  21677.  
  21678.  
  21679.  
  21680.  
  21681.  
  21682.  
  21683.  
  21684.  
  21685.  
  21686.  
  21687.  
  21688.  
  21689.  
  21690.  
  21691.  
  21692.  
  21693.  
  21694.  
  21695.  
  21696.  
  21697.  
  21698.  
  21699.  
  21700.  
  21701.  
  21702.  
  21703.  
  21704.  
  21705.  
  21706.  
  21707.